Quantcast
Channel: Questions in topic: "count"
Viewing all articles
Browse latest Browse all 187

Collecting 2 items at a time by mistake.

$
0
0
I have a very simple game where the goal is to collect 15 stars. Everything works fine except that some of the stars count for 2 points instead of 1. I tried deleting the stars that get counted twice, but it changes every time. If I play it, a star will be counted once, then the next time I play it, maybe that star gets counted as 2 points. Its very random and I dont know why its happening. I only want each star to be worth 1 point. using UnityEngine; using System.Collections; public class Collect : MonoBehaviour { public GUIText countText; public GUIText winText; private int count; void Start () { count = 0; SetCountText (); winText.text = ""; } void OnTriggerEnter(Collider other) { if(other.gameObject.tag == "Star") { other.gameObject.SetActive(false); count = count + 1; SetCountText (); } } void SetCountText () { countText.text = "Stars: " + count.ToString(); if(count >= 15) { winText.text = "YOU WIN!"; } } }

Viewing all articles
Browse latest Browse all 187

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>