CineMachine to follow a spawned Player

Hello!
I would like to spawn a player (maybe he dies and re-spawn) and then Cinemachine would set target on him and follow.

So I …

using Cinemachine;

public class SpawnManager : MonoBehaviour
{

    public GameObject player;
    public CinemachineVirtualCamera myCinemachine;


    void Start()
    {
       Instantiate(player, new Vector3(-8f, -2f, 0), Quaternion.identity);
        myCinemachine = GetComponent<CinemachineVirtualCamera>();

    }

    private void Update()
    {
        myCinemachine.Follow = GameObject.FindGameObjectWithTag("Player").transform;
    }


}

Of course It does not work! :stuck_out_tongue: I put it in Update so … may be it is always updating!

How can I assign the transform to follow to my camera?

thanks a lot as usual for your help! :*

Giovanni

This is not a useful diagnosis. Instead, break it down to isolate where things are going wrong.

I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run?
  • what are the values of the variables involved? Are they initialized?

Knowing this information will help you reason about the behavior you are seeing.

How to report problems productively in the Unity3D forums:

http://plbm.com/?p=220