Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

UI Text showing weird string value?

$
0
0
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][1] And this is the string value on the script that is being referenced: ![alt text][2] [1]: /storage/temp/69065-glitch.png [2]: /storage/temp/69066-glitch-2.png 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

Viewing all articles
Browse latest Browse all 1875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>