Hello everyone. So my problem is -I am making an endless runner and I am using an orthographic camera which follows the player. I have made a powerup that changes the current player into a wolf for certain amount of time. The problem is when the player changes into wolfr,the camera no longer follows the wolf as the primary target is disabled. How do i make the camera to follow the wolf as well?
Since you don’t supply your code, I’m going to give you a quick rundown of a possible solution.
You can tag the player and the wolf something like ‘PrimaryForm’ and ‘SecondaryForm’ respectively. I guess you are using transform.LookAt for the camera, so as to target the player. Change your code so that the camera looks at the PrimaryForm. Then, include a condition when you grab the power-up so that the camera looks for the object tagged as ‘SecondaryForm’ and changes its LookAt target to that.
In your case you could do something like this:
Where in your code are you deactivating the "Player " and activating the “Wolf”?
Since you are currently not giving us the complete code, ill just respond with some pseudo code on how you could be doing what you need.
1)Access the “target” on your camera script
2)Assign the new target.
public void ActivateWolf(){
//*// Your activating wolf function code //*//
//Get the script on your main camera.
MyCameraFollowScript followScript = Camera.main.GetComponent<MyCameraFollowScript>();
//Set the target to the wolf transform.
followScript.target = wolf.transform;
}
https://docs.unity3d.com/352/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
Just add new method in your camera follow script :
public transform newWolf;
void ChangeTarget()
{
target = newWolf;
}
just when you wont to change target just call ChangeTarget(); method