Am developing a Deer Saving Game. The idea of game is to save the deers from wolf attack.
FPS will shoot the wolf.I used nev mesh for chasing.
But the problem is this when i shoot the wolf or deer this exception originates…
“MissingReferenceException: The object of type ‘Transform’ 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.”
Can any one help???
Nav mesh Script on deer…
public Transform enemy;
public Transform gaurd;
static bool dead=false;
//public Transform target1;
//public Health character;
NavMeshAgent agent;
void Start () {
agent= GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update () {
var Distance = Vector3.Distance (enemy.position, transform.position);
var Distance1 = Vector3.Distance (gaurd.position, transform.position);
if (GameObject.FindWithTag ("Enemy") == null)
{
animation.CrossFade ("idle2");
//Application.LoadLevel("SomeLevel");
}
else
{
if (Distance > 1 && Distance <= 3)
{
agent.SetDestination (gaurd.position);
animation.Play ("getHit");
}
else if (Distance > 5 && Distance <= 30)
{
agent.SetDestination (gaurd.position);
animation.Play ("run");
//character.playerInCombat(0);
}
else if (Distance > 30 && Distance <= 100)
{
agent.SetDestination (gaurd.position);
animation.Play ("walk");
//character.playerInCombat(0);
}
else if (Distance1 < 5) {
//GameObject.FindWithTag("Enemy").destroyed;
// animation.CrossFade("idle1");
animation.CrossFade ("idle2");
//character.playerInCombat(0);
}
}
}
Nav mesh Script on Wolf…
public Transform target;
// public Transform Player;
public Health character;
public float remaining;
//public Transform target1;
//public StagHealth character;
NavMeshAgent agent;
void Start () {
agent= GetComponent<NavMeshAgent>();
remaining=agent.remainingDistance;
}
// Update is called once per frame
void Update () {
var Distance = Vector3.Distance (target.position, transform.position);
if (GameObject.FindWithTag ("Enemy") != null) {
if (Distance > 1 && Distance <= 2) {
print (remaining);
agent.SetDestination (target.position);
animation.Play ("standBite");
//animation.CrossFade("attack2");
//character.OnCollisionEnter();
// character.playerInCombat(1);
// character.ApplyDamage(1);
} else if (Distance > 2 && Distance <= 3) {
print (remaining);
agent.SetDestination (target.position);
animation.Play ("runBite");
//animation.CrossFade("attack2");
//character.OnCollisionEnter();
// character.playerInCombat(1);
} else if (Distance > 10 && Distance <= 40) {
print (remaining);
agent.SetDestination (target.position);
animation.Play ("run");
//character.ApplyDamage(1);
//character.playerInCombat(0);
//agent.SetDestination(target.position);
} else if (Distance > 40 && Distance <= 200) {
print (remaining);
agent.SetDestination (target.position);
animation.Play ("walk");
//character.playerInCombat(0);
// agent.SetDestination(target.position);
} else if (Distance > 200) {
// animation.CrossFade("idle1");
animation.CrossFade ("howl");
}
}