The score/count only goes to 1 and not further.
Using C# script.
Basically, I have a game where when you click an object it is destroyed and you get a point.
However, because i am using spawning with clones the score only ever goes up to 1. From searching internet is suggests that because the object is deleted the script is reset for the clone, the score never goes up to 2 etc.
I am trying to make a script for another non-destroyed empty game object that could do the counting. I am unsure how to do it.
This is the script the object that is destroyed (a bomb) has attached to it.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class DestroyBomb : MonoBehaviour {
public Text countText;
private int count;
void start ()
{
count = 0;
SetCountText ();
}
void OnMouseDown()
{
Destroy(gameObject);
count = count + 1;
SetCountText ();
}
void SetCountText()
{
countText.text = "Score: " + count.ToString ();
}
}
Your answer
Follow this Question
Related Questions
how to move a gameobject based on a dice roll 1 Answer
Help! Script won't work. 1 Answer
Template object and script,GameObject scripts duplicated from a template game object 0 Answers
Having multiple UNET errors that I believe are caused by unity itself. Am I doing something wrong? 1 Answer
Disable 2 Scripts during Countdown 1 Answer