I followed the roll-a-ball tutorial and camera worked and followed the player, but when I made the game multiplayer and it was spawning players as Player(Clone), I tried to remake the script as following (because it’s not working if I put a prefab onto the main camera):
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour {
private GameObject rb;
private Vector3 offset;
void Start ()
{
GameObject player = GameObject.FindWithTag ("Player");
player = rb;
rb.GetComponent<GameObject> ();
offset = transform.position - rb.transform.position;
}
void LateUpdate ()
{
transform.position = rb.transform.position + offset;
}
}
And it was giving me this error (object reference not set to an instance of an object) … I don’t know what I did wrong… I’m appreciating any response …