- Home /
How do I make an event that occurs only when application first launched?
I have a lives variable, and when I play my game I start out with 0 lives. How do I make it so that just on the time the application is first launched, you get 10 lives. NOTE: Lives is a public static int if that makes a difference.
Answer by aldonaletto · Sep 02, 2014 at 11:56 PM
A static variable is initialized only once when the game starts, thus initializing it with 10 would make live start with this value every time you run the game:
public static int lives = 10;
But if you want the variable to start with 10 only the first time you run the game, save it with PlayerPrefs routines and restore the variable at Start.
Answer by Thewhiteaura · May 26, 2015 at 06:34 AM
If you are interested, you could also make a bool variable such as "firstTimePlaying" or such and set it to true, and when the user enters into the game, have a simple check that sets it to false so that you may add additional logic to the "lives" int
Your answer
Follow this Question
Related Questions
How to make a GUI Button shrink when pressed 4 Answers
How do I set my android app to landscape mode entirely? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
GUI trouble 1 Answer
Trouble with lives 1 Answer