What is a script I can use to store data and then how would I display that data on the screen as numbers (I want to use it to make a score system,) also, how do I reference numerical values from other scripts (EX: Trigger A is activated and Value B in Script C increases by X)?
Thank you.
Hiya,
For storing the scores you can use PlayerPrebs…
PlayerPrefs is suitable for scoring scores and other data between runs of the application, but I’m guessing the OP just wants to know (or at least also wants to know) how to store the score while the game is running.
Yeah Jesse, I want to know what scripts to use to do both. I want to be able to display the score during a game and how to save it for latter (ex: displaying the player’s top 5 scores in a separate scene). How would that happen? Thanks.
Someone may post a complete script or set of scripts for you, but meanwhile I’ll offer some suggestions.
First, you might try searching the forums for e.g. ‘score’ or ‘display score’; you may be able to find some examples that way.
Regarding tracking the score while the game is running, an easy, low-tech solution would be to use a public static variable. It’s not necessarily the best solution software-design-wise, but it’s very straightforward and you won’t have to worry about figuring out how to access the data.
For displaying the score, a straightforward method would be to use OnGUI() and the GUI ‘label’ control (see the docs for details).
For saving scores between application runs, you’ll want to use the appropriate PlayerPrefs ‘set’ and ‘get’ functions - most likely SetInt() and GetInt().
If that doesn’t help, then I’d recommend asking some more specific questions and posting whatever code you have so far. (E.g. ‘Here’s my code for displaying a number onscreen - I’m not getting any errors, but I don’t see anything.’)