I’ve a problema with my script, when player colision on contact with enemy it stop and says in console.
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.
UnityEngine.Transform.get_position () (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/MetroEditorExtensionsGenerated/UnityEngineTransform.cs:28)
FollowPlayerScript.Update () (at Assets/Scripts/FollowPlayerScript.cs:23)
This is my script.
using UnityEngine;
using System.Collections;
public class FollowPlayerScript : MonoBehaviour {
public Transform Objetivo;
public float Velocidad= 3;
//Desactivado por ser utilizado en 2D
//public float velocidadRotacion= 3;
public Transform myTransform;
void Awake (){
myTransform = transform;
}
void Start (){
Objetivo = GameObject.FindWithTag("Player").transform;
}
void Update (){
//rotacion para mirar al jugador
myTransform.position = Vector2.MoveTowards(myTransform.position,Objetivo.position, Velocidad * Time.deltaTime);
//Se mueve directo al jugador
myTransform.position += myTransform.forward * Velocidad * Time.deltaTime;
}
}