I’m very new to Unity, and game dev in general, so if possible, talk to me like I’m two?
I’m creating a simple game where there are four coloured balls and four coloured holes. The objective is to get the balls into the corresponding holes.
Here’s what I want the scoring system to be like:
Get a ball into the right hole: +1
Get a ball into the wrong hole: -1
I have one script for each trigger, they all look the same (besides for the name of the colours) but this is the one for the green trigger:
void Start ()
{
Count = 0;
Score.text = "Score: " + Count.ToString ();
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Green"))
{
Count = Count + 1;
Score.text = "Score: " + Count.ToString ();
other.gameObject.SetActive (false);
}
if (other.gameObject.CompareTag ("Blue"))
{
Count = Count - 1;
Score.text = "Score: " + Count.ToString ();
other.gameObject.SetActive (false);
}
if (other.gameObject.CompareTag ("Red"))
{
Count = Count - 1;
Score.text = "Score: " + Count.ToString ();
other.gameObject.SetActive (false);
}
if (other.gameObject.CompareTag ("Yellow"))
{
Count = Count - 1;
Score.text = "Score: " + Count.ToString ();
other.gameObject.SetActive (false);
}
}
Expected behavior: The score gets increased when I get a ball into the right hole, and decreased when getting one into the wrong hole, making the maximum score 4, and minimum -4.
Examined behavior: It works fine for the first ball, but then things start to get weird. If I get the first ball right, the score wont increase anymore (it will stay at 1). Same goes for getting one in the wrong hole (it will stay at -1).
Note: I’e also tried adding another ball to see how it would behave if I got two of the same coloured balls in the right hole. This seemed to work fine, the score went to 2 but the rest of it still didn’t work. This is why I’m assuming it’s a problem with the multiple triggers.