Attempting to make a canvas appear when my first person character appears within a certain range of an object. For example, I would like a label for an object to pop up when I reach, say 2 meters from the object. Have tried a few times with different code online but I can’t find anything that works. Could someone give me pointers on how I can do this? Also how do you recommend I begin to learn C#?
Good day.
Best wat is to use Vector3.Distance() in the object itself.
If all objects have a script, just need to
if (Vector3.Distance (Player.transform.position,gameObject.transform.position) <= 2)
{
CanvasObject.SetActive(true);
}
else
{
CanvasObject.SetActive(false);
}
But this solution require that all objects have its own script.
The other solution is to have a collider marked as trigger in the player, and detect all the objects inside the collider. When they are inside, open the canvas from the player script.
If can not do these things (they are very very basic) you need to watch more tutorials, examples and manuals!
Bye!