Question by
NaregJan · Aug 23, 2016 at 11:58 AM ·
javascriptcanvaschild object
How do I get this Canvas to disappear?
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.
Comment