How to properly set-up the count of object on collision?
I am trying to set-up a score, where my player enters in collision with a collectible called "Gold". The collision works fine and when it happens the collectible disappears. However, when I want to attach this to a score, I am only able to increase the score of 1, with the first collectible. The others collectible when touched, correctly disappear, but do increase the count. Why is that? The script at the moment is attached to the collectible.
{
public class GoldController : MonoBehaviour { public GameObject Player; public Text ScoreText;
private int score;
// At the start of the game..
void Start()
{
// Set the count to zero
score = 0;
SetScoreText();
}
void OnTriggerEnter(Collider Player)
{
// We check if the object we collided with has a tag called "Obstacle".
if (Player.GetComponent<Collider>());
{
gameObject.SetActive(false);
// Add one to the score variable 'count'
score = score +1;
// Run the 'SetCountText()' function (see below)
SetScoreText();
Debug.Log("Cool");
}
}
void SetScoreText()
{
ScoreText.text = "Score: " + score.ToString();
if (score >= 2)
{
Debug.Log("Cool");
}
}
}
Your answer
Follow this Question
Related Questions
my counter wont change from 0 help 1 Answer
How to Switch GameObjects (Weapons) by reaching a specific amount of score? 0 Answers
multiple score counts UI 0 Answers
Increasing score based on speed 1 Answer