Continuing my last post, today I write the command that delete the pipe when it is go over the screen game. Learn how to add a text into the screen game, and made it change to another number when click a button.
In the PipeMoveScript, create a deadZone is -45 and check if the pipe’s x-coordinate is smaller than the deadZone, destroy the pipe.
And also how to use the Debug.log same as print in python to print Pipe Deleted when it deleted the pipe.
Next to create text, right click on UI -> Legacy -> Text. And in the text object we can change the position, font size and font color. After playing the game, you can see text on the screen.
Next is to create a new object named Logic Manager and a new script named LogicScript. In LogicScript, create 2 variables: playerScore, ScoreText. Create a contextMenu (this command is like a function in Python, we can call it when needed) called Increase Score. In this function, add 1 to playerScore and ScoreText equals playerScore. Return to the Unity, and move the text object to the Logic Manager object’s ScoreText. So it can connect the text to the player’s score. When the game is playing, the text will add 1 when we call the Increase Score() function in the right corner of the screen.
No Responses