when my player dist from enemy it’s show this.
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.
public class follow : MonoBehaviour
public Transform player;
private NavMeshAgent agent;
// Start is called before the first frame update
agent = GetComponent<NavMeshAgent>();
// Update is called once per frame
agent.destination = player.position != null;
This code requires the
player object to be always available for the script to work, as you are accessing its position in every frame.
If that’s not guaranteed, you could check that
player is available before setting the agent destination.
agent.destination = player.position;
Note also that
agent.destination is a
Vector3, so even if player existed, you cannot assign
player.position != null (a boolean) to it.
Thank you for ur reply. I would like to be like you knowing these Things. So can u gied me from where should i start learning.
In terms of learning, I personally completed this Unity course long time ago, and it was super clear to get started with scripting.
Good luck on your journey.