Question by
l_blackwell_thale · Oct 19, 2016 at 01:51 PM ·
uiscoremultiplescore systemcount
multiple score counts UI
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<Rigidbody> ();
count = 0;
SetCountText ();
}
{
rb = GetComponent<Rigidbody> ();
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 ();
}
}
Comment