Hello,
I have this script that checks when the enemy is close to the player and if it is it takes away some health, here it is
#pragma strict
var Health = 100;
var Enemy : Transform;
var MoveSpeed = 4;
var AttackRange = 1;
var MinDist = 0;
function Start () {
}
function Update () {
if(Vector3.Distance(transform.position,Enemy.position) >= MinDist){
transform.position += transform.forward*MoveSpeed*Time.deltaTime;
if(Vector3.Distance(transform.position,Enemy.position) <= AttackRange)
{
Health -= 1;
//Here Call any function U want Like Shoot at here or something
}
if (Health <= 0) {
Health = 0;
}
if (Enemy == null) {
}
}
}
function OnGUI () {
GUI.Label (Rect (10, 10, 100, 20), "Health = " + Health);
}
but my problem is that when i destroy the Enemy it filles the console with messages saying "the object of type transform has been destroyed but you are still trying to access it. how would i stop trying to access it?
Thanks,
Joseph