I'm trying to spawn the Player and attach the Player.transform to CinamachineVirtualCamera.Follow to make the camera follow the player. And here is my script.
using Cinemachine;
using UnityEngine;
public class GameManager : MonoBehaviour
{
public static GameManager sharedInstance = null;
private SpawnPoint playerSpawnPoint;
private CinemachineVirtualCamera camFollowPlayer;
private void Awake()
{
if (sharedInstance != null && sharedInstance != this)
Destroy(gameObject);
else sharedInstance = this;
}
private void Start()
{
playerSpawnPoint = GameObject.Find("PlayerSpawnPoint").GetComponent<SpawnPoint>();
SetupScene();
}
public void SetupScene()
{
SpawnPlayer();
}
public void SpawnPlayer()
{
if (playerSpawnPoint != null)
{
GameObject player = playerSpawnPoint.SpawnObject();
camFollowPlayer.Follow = player.transform; //my code got error NullExceptionReference here
}
}
}