Some Error

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

public class EnemyController : MonoBehaviour
{
    public float speed;
    public float health;
    public int playerDamage = 5;
    public Text kd;

    float damage;
    int Deaths;
    Transform Player;
    Rigidbody rig;
    ParticleSystem part;

    void Start()
    {
        GameObject player = GameObject.Find ("Player");
        Shoot shot = player.GetComponent<Shoot> ();
        damage = shot.damage;

        part = gameObject.GetComponent<ParticleSystem> ();
        rig = gameObject.GetComponent<Rigidbody> ();
        Player = GameObject.FindGameObjectWithTag ("Player").transform;

        kd.text = "Kills: " + Deaths;
    }

    void Update()
    {
        if (health <= 0)
        {
            StartCoroutine (Death());
            Deaths = Deaths + 1;
            kd.text = "Kills: " + Deaths;
        }
        gameObject.transform.LookAt (Player);
        transform.Translate (0.0f,0.0f,speed * Time.deltaTime);
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag ("Shard"))
        {
            part.Emit (1);
            health -= damage;
            Destroy (other.gameObject);
        }
    }
    public IEnumerator Death()
    {
        part.startColor = Color.red;
        part.Emit (1);
        yield return new WaitForSeconds(0.25f);
        Destroy (gameObject);
    }
}

When ever I try and start this the line ‘kd.text = "Kills: " + Deaths;’ gives me the error NullReference

I don’t know what is wrong with it

When you get a null ref error, it means something is null. So either kd is null, or Deaths is null. But Deaths is an int, which means it isn’t going to be null. (we’ll ignore nullable types). Which means kd is null.

So the question is, what makes kd null? There isn’t anything assigned to it. So there are a few things. Either you didn’t drag something into the inspector field or you have multiple copies of EnemyController and one of them is coming up null.

And always a good idea to just post the entire error from the console. :slight_smile:

Have you dragged the ‘kd’ Text object to the proper slot on the script?

yes i have, and ya i do have multiple copies, but they all have values

If they all have values for ‘kd’ properly attached, then something is wrong. The ‘kd’ should point to a text object in the scene. Beyond that, I’m not sure what could be wrong…