Hi,
i have some trouble understanding the difference between assigning a Gameobject via drag&drop vs using Gameobject.Find
i have an abstract Enemy class, which looks like this:
public abstract class Enemy : MonoBehaviour
{
public float speed = 5;
public GameObject player;
public void Move()
{
transform.position = Vector3.MoveTowards(transform.position, player.transform.position, Time.deltaTime*speed);
}
I assign the player Gameobject in the Unity editor (i have to make a Prefab of the Player to be able to assign it with drag&drop)
the Child Class EnemyEasy calls the Move() method in its Update method.
The Enemy Gameobject as the EnemyEasy script attached to it.
This is the result:
The Enemy Gameobject moves towards the starting position of the player.
but as soon as the player moves away, the Enemy wont follow him.
Why is that?
If I use player = GameObject.Find("Player"); in the Start() method of the abstract class, everything works fine. The enemy follows the player, even if the player moves away.
But if i assign the Player Prefab Gameobject via drag&drop, the enemy just moves to the starting position of the player.