Skip to main content
2 of 2
Re-formatted the code fragment to make it more readable. also fixed an error (typo) in 'Transform'

you just can change reference to FollowGoal by any moment you want.

Transform FollowGoal;
Transform Enemy1;
Transform Enemy2;
    
void Update()
{
    if(Input.GetKeyDow(KeyCode.1)) 
    {
        FollowGoal= Enemy1;
    }    

    if(Input.GetKeyDow(KeyCode.2)) 
    {
        FollowGoal= Enemy2; 
    }

    Transform.position= Vector3.MoveTowards(transform.position, FollowGoal.position,speed);
}
```
virtouso
  • 2.7k
  • 7
  • 44
  • 69