using UnityEngine;
using System.Collections;
public class ball_controller : MonoBehaviour {
public float speed;
public Text amountText;
private Rigidbody rb;
private int amount;
void Start ()
{
rb = GetComponent<Rigidbody>();
amount = 0;
SetAmountText ();
}
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("Dot"))
{
other.gameObject.SetActive (false);
amount = amount + 1;
SetAmountText ();
}
}
void SetAmountText ()
{
amountText.text = "Amount: " + amount.ToString ();
}
}
I get the error:
MissingReferenceException: The object of type ‘Object’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
and
Assets/_Scripts/ball_controller.cs(7,16): error CS0246: The type or namespace name `Text’ could not be found. Are you missing a using directive or an assembly reference?