Question by
walkerdude5 · Jul 27, 2017 at 11:39 PM ·
unity 5playerprefsvariables
Script variables on gameObject in resource folder are not retained unless I inspect it before I press play
I am making a skill tree and the values for the variable are not being retained.
Here is example code for a variable that defaults to zero unless I inspect it before hitting play Code attached to gameObject in resource folder:
public class ability3Script : MonoBehaviour{
public int AB3dmg;
...
void update()
{
PlayerPrefs.SetInt("AB3dmg", AB3dmg);
}`
This code is attached to a button and is ran onclick.
Ability3.GetComponent<ability3Script>().AB3dmg++;
PlayerPrefs.SetInt("AB3dmg", Ability3.GetComponent<ability3Script>().AB3dmg);
Comment