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

Score system not working

$
0
0
I am wanting to pick up a prefab, "Gem", and for the system to add 10 points. I have the scoreText visible on screen, but it doesn't add 10. Here is the code: using UnityEngine; using System.Collections; using UnityEngine.UI; public class RandomSpawn : MonoBehaviour { public GameObject Gem; private int count; public Text countText; void Start() { count = 0; SetCountText (); } void SpawnGem() { Vector3 RandomSpawn = new Vector3 (Random.Range (-8.87F, 8.87F), Random.Range (-3.87F, 3.97F),1F); Instantiate (Gem, RandomSpawn, Quaternion.identity); } void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.CompareTag ("Player")) { SpawnGem (); Destroy (Gem); count = count + 1; SetCountText (); } } void SetCountText() { countText.text = "Count: " + count.ToString (); } }

Viewing all articles
Browse latest Browse all 187

Trending Articles



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