• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Harryliu · Apr 29, 2016 at 04:02 AM · scripting problemjavascriptuiraycasttext

UI Text showing weird string value?

I have t$$anonymous$$s script that essentially selects an object using Raycast and displays the name of it via Text UI. Everyt$$anonymous$$ng works fine, but the text that appears on screen when the object is selected is not what I want. T$$anonymous$$s is what I see: alt text

And t$$anonymous$$s is the string value on the script that is being referenced:

alt text

And here is the script:

 #pragma strict
 import UnityEngine.UI;
 
 var cam : Transform;
 var layerMask : LayerMask;
 var mat : Material;
 var selectedObject : GameObject;
 var Text : Text;
 var objText : String;
 private var showObj : boolean;
 
 function Start () {
 
 }
 
 function Update () {
 
     var ray = new Ray(cam.position, cam.forward);
     var $$anonymous$$t : RaycastHit;
 
     if(Physics.Raycast(cam.transform.position, cam.forward, $$anonymous$$t, 100, layerMask))
     {
         selectedObject = $$anonymous$$t.transform.gameObject;
         objText = selectedObject.GetComponent(Item).objName;
         SelectObject(selectedObject);
         Debug.Log("You $$anonymous$$t " + objText);
         showObj = true;
         ShowSelectedObject(selectedObject);
     }
 
     else
     {
         ClearSelection();
     }
 }
 
 
 function ShowSelectedObject(sobj : GameObject)
 {
     if(showObj == true)
     {
         Text.text = ("" + objText.ToString);
     }
 }
 
 function SelectObject(obj : GameObject)
 {
     if(selectedObject != null)
     {
         if(obj == selectedObject)
         {
             return;
         }
         ClearSelection();
     }
 
     selectedObject = obj;
 
 }
 function ClearSelection()
 {
     Text.text = null;
     selectedObject = null;
     showObj = false;
     objText = null;
 }


Little help here? thanks

glitch.png (66.3 kB)
glitch-2.png (16.0 kB)
Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Taorcb · Apr 29, 2016 at 04:08 AM

Try changing Text.text = (" + objText.ToString); to Text.text = objText;

Comment
ahmed-yehia

People who like this

1 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Harryliu · Apr 29, 2016 at 04:16 AM 0
Share

Wow that was an easy fix thanks for your answer :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

90 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problems in the script for making a text disappear after few seconds 2 Answers

Inspector changes set TextMeshPro values on play 1 Answer

sending a variable to a text object 1 Answer

Problem with UI Text displaying a score 0 Answers

Display the same string in multiple text boxes 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges