So I have made a pinball type game with 2 balls and about 40 coins. On each coin I have a script that I will link to the post. However after a ball collides with the first coin it will set the countText in the top right corner to 1 and then ignore the other coins. However the balls still collide with the other coins and set them inactive but they won't count them. Help?
public Text countText;
public Text winText;
private Rigidbody2D rb2d;
private int count;
void Start () {
{
rb2d = GetComponent ();
winText.text = "";
count = 0;
SetCountText ();
}
}
void Update () {
}
void OnTriggerEnter2D(Collider2D other)
{
Debug.Log ("Triggered!");
gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
void SetCountText()
{
countText.text = "Count: " + count.ToString ();
if (count >= 42)
winText.text = "You win!";
}
}
↧