Question by
Wizards_And_Mages · May 30, 2016 at 02:42 PM ·
variable
Variable keeps value after closing app
Hello, I have spell cooldown variable :
private float nextFire = 0;
public bool IsOffCooldown()
{
return Time.time > nextFire;
}
public void Cast(Transform spellSpawnerTransform)
{
nextFire = Time.time + FireRate;
Instantiate(this, spellSpawnerTransform.position, Quaternion.identity);
}
once i close the app the variable nextFire keeps it's previous value i.e if the last time the game went on for let's say 30 secs the nextFire variable will have 30f as starting value. Why ? How to fix this ?
Comment
Is it possible that you don't call these functions on an instance but on a gameobject that you have assigned through inspector or loaded with resources.load?
I found the problem it was that I edited the prefab ins$$anonymous$$d of the instance as you mentioned. How can i fix that ?
It's hard to say without seeing the whole script or knowing what it's attached to but usually you want to create an instance of the gameObject first, get this component and do all operations on it.