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