- Home /
death count resets after re-loading scene
deahtAds script:
public int death;
private static readonly Dictionary <String, String> REVMOB_APP_IDS = new Dictionary <String, String>() {
}
};
private RevMob revmob;
private RevMobFullscreen fullscreen;
// Use this for initialization
void Awake () {
DontDestroyOnLoad (this);
revmob = RevMob.Start(REVMOB_APP_IDS, "Ads");
}
void Start(){
#if UNITY_ANDROID
RevMobBanner banner = revmob.CreateBanner(RevMob.Position.BOTTOM, 0, 0, Screen.width, 100);
banner.Show ();
#elif UNITY_IPHONE
banner = revmob.CreateBanner(0, 0, 350, 50, null, null);
banner.Show();
#endif
}
// Update is called once per frame
void Update () {
Debug.Log (death);
if (death > 2) {
death = 0;
revmob.ShowFullscreen();
}
}
}
and in my main character script, when the player dies it supposed to add + 1 to public int death, and when gets to 3 show an ad and reset itself. this is how i add:
deathscript.death += 1;
in awake function im getting the script deathAds. even tho im using dontdestroyonload, it still does destroy it, and begins the count all over again.
What script has this Awake function that is refencing the deathAds script?
How are you reloading the scene?
Also the deathAds needs to have in awake/start DontDestroyOnLoad too. $$anonymous$$ake sure to pass the reference to the gameobject it is attached to!
I don't think that SirBobo really need DontDestroyOnLoad here anyway, for just saving death count static variable is a better idea along with removal of "incorrectly coded" Line#8, unless that is needed for Rev$$anonymous$$ob.
P.S. Though I guess if script holder is a player then it gets destroyed anyway on death (if player is), in that case that won't work even if Rev$$anonymous$$ob needed it.
Answer by DoTA_KAMIKADzE · Apr 10, 2015 at 09:51 PM
public static int death;
I've tried this before, the problem is that I get an error since im trying to call a static variable in a different script, I can't use get component,and i dont really know how to get static variable.
You don't need to call it using instance of your class, just:
ClassName.VariableName;
In your case it should be:
deahtAds.death += 1;//if from another script
//or if from same you can do as this as well:
death += 1;
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Setting public GameObject to a different Prefab through code 0 Answers
Get the amout of objects in a given position 1 Answer
Enum Count 2 Answers