- Home /
Question by
kmcarlson94 · Oct 20, 2014 at 09:33 PM ·
timetimerhow-to
How to make an enemy morph based on a timer?
Basically, I want to make an enemy change it's stats (damage, health, and looks) after a certain period of time. The timer should be based on when the enemy appeared, not on how long the game has been running. Is this possible?
Comment
Answer by mwbranna · Oct 20, 2014 at 09:49 PM
Store "Time.time" when the enemy is created, and compare that to the current game time in Update()
The below code isn't tested so may contain compile errors but the overall concept remains.
private float startTime = 0f;
public float changeAfterSeconds = 3f;
private bool changed = false;
void Start(){
startTime = Time.time;
}
void Update(){
if(!changed && Time.time > startTime + changeAfterSeconds){
//do things
changed = true;
}
}
Your answer
Follow this Question
Related Questions
How to make a timer read to the .001 of a second 2 Answers
Minute Timer Issue 1 Answer
Game Timer help needed 2 Answers
How accurate is Stopwatch.ElapsedTicks? 0 Answers