简体   繁体   中英

Find the value of a text box in Unity with c#

In my game that I'm creating I have a textbox that has the value of the amount of lives the character has. I want to know how to check that value so I can then use that data to change scenes, for example: if the text box is five and going down I want to check when (lives = 0); then to change the scene. Also, if anyone knows the code to change scenes that would be very helpful.

You should just keep a variable with the number of lives so you don't have to fetch it from a text box or any other element. When the game starts, set lives = 5 . Then each time the user dies, decrease this variable by 1.

The textbox (or better yet just a static label) should only be used for display, not for retrieval. Make sure to keep the variable available so you can use it directly to decide when the game is over.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM