The object of type 'Transform' has been destroyed but you are still trying to access it.

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");

						}
				}

In one script you are trying to get the position from a certain object with Transform.
But somwehere throughout the game this object is either destroyed or not accesable anymore.

You gotta let the game know that when the object is destroyed or not accesable anymore to not use the Transform anymore.

I did this myself with creating a state ‘GameOver’. So the transform is only accesed when gameover is equal to false.

you can choose to only do the code by checking if object exists:

if ( deer.gameObject ) {code here}

if (deer.gameObject != null ) { code here }

Finaly i Resolve this issue by using

if(enmey)

 if(enemy){ 
     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);
                            }
                    }
     
            }
    }
    else
    {
    agent.Stop(true);
    }