THE LANGUAGE I AM USING IS C#!
Hello there, so I have been messing around with my script for a while now and I am trying to get it so when i look away from a collider object that the UI is disabled. I am using simple UI canvas and SetActive statements.
But I’m not sure where I can place the code or how I’d write the code to disable the UI when you look away from the item that is tagged “FoodItem” and “WaterItem”.
Here is the code I Use when looking at the item to enable the UI, but when I look away from the item the canvas is still on my screen…
if (Physics.Raycast(ray, out hitinfo, interactRange))
{
if (canHover = true)
{
Debug.Log("Tesing");
if (hitinfo.collider.tag == "FoodItem")
{
eatFood.SetActive(true);
drinkWater.SetActive(false);
Debug.Log("Looking at food!");
}
if (hitinfo.collider.tag == "WaterItem")
{
eatFood.SetActive(false);
drinkWater.SetActive(true);
Debug.Log("Looking at water!");
}
}
}
}
This script is using variables from another script also. can anyone help me to be able to disable the two canvases when not looking at them please.
Thanks guys <3