Pardon me if I wasn’t understandable with my question header, but I want to add “/12” after my score that I’m showing on the canvas.
Note that I was following the project “Roll a Ball” on the unity website and just wanted to make this small tweak where I show the total number of collectibles along with the currently collected. Something like “Collected: n/12” “n” being the current score.
I’m completely new hear, so pardon me again if I wasn’t understandable. I lack the knowledge jargon too.
Here’s the whole code where I’ve put the scoring text:
using UnityEngine.UI;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
public Text escapeInfo;
private Rigidbody rb;
private int count;
private string total;
void Start ()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText ();
winText.text = "";
escapeInfo.text = "";
}
void Update ()
{
if (Input.GetKey (KeyCode.Escape))
Application.Quit ();
}
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("Pick Up"))
{
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Collect: " + count.ToString ();
if (count >= 12)
{
winText.text = "You Win";
escapeInfo.text = "Press "Esc" to Exit";
}
}
}