Question by
ioshi35 · Oct 30, 2016 at 04:47 PM ·
playerprefsscore
Unity getting the score
Hello my problem is I have a lot of game object and theres a same script on it.
there's a int variable on every game object . but every time I do this .. count +=5;
the only output is 5 its never increasing .. I know its because its all the same script on each object .. I wanna know a way to increase it
I tried Playerprefs but no luck
Comment
Best Answer
Answer by Cynikal · Oct 30, 2016 at 06:03 PM
The score should be on a single gameobject... Call it "ScoreKeeper".
Once you want to add the score.. say from your smaller objects, you could do:
GameObject.Find("ScoreKeeper").GetComponent().MyScore += 5;
That is one example of doing it. You'd ideally want to set your score keeper as a singleton, so you don't have to continuously use GameObject.Find.