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

How do I get this Canvas to disappear?

$
0
0
Hey! So I've got a JS script that I want to use to make a canvas disappear and reappear when its parent is raycast at. Here is the script: #pragma strict function Update() { if (Input.GetMouseButtonDown(0)){ var ray = Camera.main.ScreenPointToRay(Input.mousePosition); var hit : RaycastHit; if (Physics.Raycast(ray, hit)){ var person: Canvas = hit.collider.gameObject.transform.parent.gameObject.transform.Find("Canvas") as Canvas; Debug.Log(person); if (person.enabled == true) person.enabled = false; else person.enabled = true; } } } The mouse click works, the getting of the parent works, but I can't access the Canvas for the life of me. It's name is "Canvas", and I've tried `.GetChild(1)` as well. The error I keep getting is `NullReferenceException: Object reference not set to an instance of an object ClickForText.Update () (at Assets/Scripts/ClickForText.js:15)`. Please help.

Viewing all articles
Browse latest Browse all 1875

Trending Articles



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