Display A Score/Points

Hello,

I am using the same pickups from the roll a ball tutorial and I have already tried the script written in the same tutorial for displaying a score. One of the key parts of it is that you have a box that you have to drag the text box element in the hierarchy into the inspector of the scripts but I do not have this box. Any other ways you know of for displaying the amount of pickups collected?

Thanks,

I haven’t done the tutorial but if your field should be listed in the inspector and it isn’t, you probably forgot to make it public. Where your variable is listed, most likely at the top of your script, add the word public before it. If you can’t get it to work, post your script using code tags!

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class PlayerController : MonoBehaviour {

public float speed;
public Text countText;
public Text winText;
...

(from the tutorial he’s referencing)

you need the “Using UnityEngine.UI;” at the top to be able to use “Text” type, and as Fujik says, the variables need to be public to expose them in the inspector (or private and [serializedfield] but you’ll get to that later :slight_smile: )

1 Like

I already had the variable public and was using the UI but i am still having this problem. is there some other way to address the canvas text instead of dragging it into the inspector as it said in the tutorial? ill post my code in a second.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class FirstPersonController : MonoBehaviour {


    public float movementSpeed = 5.0f;
    public float mouseSensitivity = 5.0f;
    
    

    float verticalRotation = 0;
    public float upDownRange = 60.0f;

    // Use this for initialization
    void Start () {
        
        

    
    }
    
    // Update is called once per frame
    void Update () {
        
        //Mouse
        float rotLeftRight = Input.GetAxis("Mouse X") * mouseSensitivity;

        transform.Rotate(0, rotLeftRight, 0);

        

        verticalRotation -= Input.GetAxis("Mouse Y") * mouseSensitivity;
        verticalRotation = Mathf.Clamp(verticalRotation, -upDownRange, upDownRange);
        Camera.main.transform.localRotation = Quaternion.Euler(verticalRotation, 0, 0);

        
        //Keyboard
        float forwardSpeed = Input.GetAxis("Vertical") * movementSpeed;
        float sideSpeed = Input.GetAxis("Horizontal") * movementSpeed;

        Vector3 speed = new Vector3 (sideSpeed, 0, forwardSpeed);

        speed = transform.rotation * speed;

        CharacterController cc = GetComponent<CharacterController> ();

        cc.Move( speed * Time.deltaTime );
    
    }

    void OnTriggerEnter(Collider other){
        if (other.gameObject.CompareTag("Cube")){

            other.gameObject.SetActive (false);
            
            

        }
    }

    
}

This was my code without the timer