- Home /
Instantiated Prefabs resetting score and not detecting tap?
Hey, Im making a game where when you tap the objects (which are Randomly Generated ) that fall down the screen, a point is added, when the Prefab is cloned the 'Score'is resets to 0... Any help? heres the Score script added to my Prefab.
using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour {
public Transform clicks;
public GUIText score;
public bool clicked = false;
public int click = 0;
public void Start (){
}
public void Update (){
score.text = "Pingas Popped: " + click;
if (click == 250)
Application.LoadLevel("Superman");
}
void OnMouseDown (){
click += 1;
}
}
Answer by Tehnique · Jul 09, 2014 at 10:50 AM
Each prefab has it's own score, which starts as 0. I don't know how you use this score, but it seems to me that it should be in only 1 place, not on all prefabs. As a simple solve, you could try to make "click" static (so only 1 value is shared by all score objects).
How could I $$anonymous$$ake "click" static, Sorry im new to coding..
Thankyou SO $$anonymous$$UCH, Technique.. You don't understand how long ive been trying to fix this, What do I do now to give you, rep points or something! :)!
Heh, it's no problem, mate, glad I could help! Remember: static values are shared by all instances, non-statics have different values for each instance.
Is your script named the same as the class inside? So "public class Score" should be inside a file named "Score".
Your answer
![](https://koobas.hobune.stream/wayback/20220613153603im_/https://answers.unity.com/themes/thub/images/avi.jpg)