Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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
0
Question by Harryliu · Apr 29, 2016 at 04:02 AM · javascriptscripting problemuiraycasttext

UI Text showing weird string value?

I have this script that essentially selects an object using Raycast and displays the name of it via Text UI. Everything works fine, but the text that appears on screen when the object is selected is not what I want. This is what I see: alt text

And this 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 hit : RaycastHit;
 
     if(Physics.Raycast(cam.transform.position, cam.forward, hit, 100, layerMask))
     {
         selectedObject = hit.transform.gameObject;
         objText = selectedObject.GetComponent(Item).objName;
         SelectObject(selectedObject);
         Debug.Log("You hit " + 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
Add comment
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
1
Best Answer

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

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

Comment
Add comment · 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.

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

Display the same string in multiple text boxes 1 Answer

Pause Menu Issue (Black Screen) 0 Answers

Hiding the part of a UI text behind a 3D object 1 Answer

Text wont change to correct value 1 Answer

TextField text component not updating 2 Answers


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