The Script Where The "count" int is.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
public Text fewLeft;
private Rigidbody rb;
public int count;
void Start ()
{
rb = GetComponent();
count = 0;
SetCountText ();
winText.text = "";
fewLeft.text = "";
fewLeft = GetComponent ();
}
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 = "Count: " + count.ToString ();
if (count >= 8)
{
winText.text = "You Win";
}
if (count >=6)
{
fewLeft.text = "Only Two Left";
}
}
}
The Script Where I Try To Access It.
using UnityEngine;
using System.Collections;
public class SetActive : MonoBehaviour {
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
GameObject pC = GameObject.Find ("Few Left Text");
PlayerController PLCO = pC.GetComponent ();
if (PLCO.count >= 8)
{
pC.SetActive (false);
}
}
}
And It Gives Me Error Message:
NullReferenceException: Object reference not set to an instance of an object
SetActive.Update () (at Assets/Scripts/SetActive.cs:18)
↧