Infinite Runner PlayerPrefs problem

I really didnt want to do this but I have spent too much time trying to figure it out. just so unity devs are aware, specifically mike geig, following along the tutorial for the infinite runner I had a few problems i had to fix. first the HUDScript wouldnt work. i copied and pasted the same code into HudScipt, still nothing, copied and pasted the same code into GuiTestScript and it worked? so the name was stopping it from working? next was something like gameObject.Find which wouldnt work, i believe i changed it to FindWithTags or something like that. other thing was where it had to find the game object “Main Camera” wouldnt work, changed it to something like Camera.main.whatever… sorry i dont remember exactly what they were but i figured it should be looked into… as for my most recent problem:

on what would be the HUDScript is

void onDisable()
{
    PlayerPrefs.SetInt ("Score", (int)(playerScore * 10));
}

and on the GameOverScript in the next scene is

public class GameoverScript : MonoBehaviour 
{
    int score = 0;
    
    void Start()
    {
    	score = PlayerPrefs.GetInt ("Score");
    }
}

but when it runs it comes up 0. its probably something simple that ive missed but like i said ive spent a lot of time trying to figure it out or find ways around it but nothing yet

yea i got that from the first answer that i said was correct. and no not all of the errors i had were grammatical. does it bother you that i dont take the time to correctly type everything on a forum? if so you live a very sad life. thank you for your unnecessary reply, but im sure you could find something more productive to do than check the unity forums for proper grammar??

I spend significant time as a volunteer here attempting to help people out, because I like Unity, I like programming, and I like teaching people. It is all easier to do when correct grammar rules are followed. My response was slightly tongue in cheek. But the point is valid. If you take the time to make sure your grammar is exact it will make you a better coder. It will also make your next question easier to understand and answer. You'll also get off the mod queue faster.

1 Answer

1

There is no onDisable function in Unity, so unless you’re calling it yourself it will never execute. Presumably you meant OnDisable. Programming is very specific and you do need to follow every step exactly.

lmao i figured it would be something as simple as that. thank you :). also i remembered one of the other things that was happening. in my script if i wrote GUI.Label nothing would show up, so i change it to GUI.Box and it works, then i change it back to GUI.Label and it works? happened on 3 separate instances on 2 different scripts..