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

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; 
trasform    }

    Transform.position= Vector3.MoveTowards(transform.position, FollowGoal.position,speed);
}
```

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;
trasform.position= Vector3.MoveTowards(transform.position, FollowGoal.position,speed);
}

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);
}
```
Source Link
virtouso
  • 2.7k
  • 7
  • 44
  • 69

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;
trasform.position= Vector3.MoveTowards(transform.position, FollowGoal.position,speed);
}