Part 1: The Problem
I encountered a challenge related to adding text above the enemy characters' heads to display their current behavior state. This was a required cheat code function so I had to implement it.
Just attaching the text component directly to the enemy object presented additional complications. It prevented the text from being freely positioned or facing the player, as it would be rigidly fixed to the enemy's position and rotation. This further limited the visibility and effectiveness of the behavior state information, reducing its overall usefulness.
Part 2: Problem Solution
Instead of attaching the text component directly to the enemy object, I created an empty child object under each enemy. This child object would serve as the holder for the text component, allowing it to be positioned independently and face the player accurately. By doing so, I gained the necessary control over the text's position and rotation, making it more visible and readable for players.
To enable the text component's visibility based on the enemy's behavior state, I established a public bool variable in the parent enemy script. This variable acted as a toggle, determining whether the text component should be turned on or off. By accessing this bool from the child object's script, I could easily control the text's visibility, dynamically showing or hiding it based on the change of the Boolean.
Implementing this solution improved the ability to freely position and rotate the text enhanced its visibility and readability.
Did you like this post? Tell us
Leave a comment
Log in with your itch.io account to leave a comment.