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

multiple score counts UI

$
0
0
Hi, I have a game where a roll a ball collides with 3 different types of collectible assets and I want the representative numbers of each asset to be shown on the UI. For example: collectible 1: (the number of this asset collected) collectible 2: (the number of this asset collected) collectible 3: (the number of this asset collected) I have managed to get one collectible to appear and work correctly, however the addition of multiple counts confuses things. This is my script so far: (NB collectible 1 is named Gull and collectible 2 is Ice Cream) Thanks using UnityEngine; using UnityEngine.UI; using System.Collections; public class PLAYERCONTROLLER : MonoBehaviour { public float speed; public Text countText; public Text countTextb; private Rigidbody rb; private int count; private int countb; void Start () { { rb = GetComponent (); count = 0; SetCountText (); } { rb = GetComponent (); countb = 0; SetCountText (); } } void FixedUpdate () { float moveHorizontal = Input.GetAxis ("Horizontal"); float moveVertical = Input.GetAxis ("Vertical"); Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical); rb.AddForce (movement * speed); } void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag ("PickupGull")) { other.gameObject.SetActive (false); count = count + 1; SetCountText (); } else if (other.gameObject.CompareTag ("PickupIcecream")) { other.gameObject.SetActive (false); } } void SetCountText () { countText.text = "Gull Count: " + count.ToString (); countText.text = "Ice cream 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>