Hey guys I have been working on this procedure for over a day and I am about at the end of my sanity…
Basically I have 2 boxes, 1 is a wall and 1 is a cube. I am trying to create a tooltip that last for a few seconds and then disappears until the move leaves the object and points to it again. So far i have got the tool tip to disappear like i wanted however after numerous seconds the Coroutine starts fight with update and starts popping in and out. I read that your not supposed to start Coroutine within Update but start however i have tried both void start and IEnumerator start with zero success of the Coroutine starting (the text never fades).
I am quite new to unity and been checking out the tutorials and examples from here and various sites but at this point i am afraid i may have got myself confused or mixed up along the way and am just lost at this point. any advice or tips would be a godsend.
Here is the script I have been working with:
public GameObject textcanvas;
private int box;
// Use this for initialization
void Start()
{
textcanvas.SetActive(false);
box = LayerMask.NameToLayer(“box”);
}
// Update is called once per frame
void Update()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
if (hit.transform.gameObject.layer == box)
{
StartCoroutine(fade());
textcanvas.SetActive(true);
print("box hit");
}
}
}
private IEnumerator fade()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
if (hit.transform.gameObject.layer == box)
{
yield return new WaitForSeconds(3);
{
textcanvas.SetActive(false);
}
}
}
}
}