In last post, we put a text message on top-left corner of screen, now we are going to add a c# script onto the text, letting it show what the user is looking at
First add a tag to the cube, name is as "cool cube"
Create a "Scripts" folder and add a c# script ShowObjectName.cs
Edit the script in Visual Studio,
Save and assign this code to the Text
play the scene in Unity, you can see the text is now showing what the cursor is aiming at
now let's explain these codes:
GameManager.Instance, if you add an InputManager into the Hierarchy, there will be a GazeManger static instance, it is a Singleton pattern, so in one scene, there will be only one GazeManager existing
when GazeManager.HitObject is not null, try to read the gameObject's tag and assign it to the Text we are showing. otherwise, showing none
No comments:
Post a Comment