I made script to enemy in my game which tells enemy which way to look/go. Script is attached to prefab. Another script instantiates prefab while playing.
public Vector3 direction;
public float speed = 5.0f;
public CharControl GetCharPosition;
void Update ()
{
direction = GetCharPosition.lastPosition - transform.position;
float enemySpeed = speed;
enemySpeed *= Time.deltaTime;
transform.Translate(direction.normalized * enemySpeed, Space.World);
transform.LookAt(GetCharPosition.lastPosition);
transform.localEulerAngles = new Vector3(0, transform.localEulerAngles.y ,0);
}
I had to grab my character from hierarchy and drop it into inspector. It works fine, but everytime I reload the scene it disappears and I have to put it back again. This also happens if I make a build from the game so I can't make a proper build. Is this a bug or am I doing something wrong?