title: Need help getting camera to follow instantiated GameObject (player)
body: <p>Working on a multiplayer game in Unity3D. Like many others, I've got some serious issues getting the camera to follow the player. In a normal game, you simply make the camera object a child of the player object to make it follow the player. In multiplayer, this is not an option as players need to spawn (prefab).</p>
  
  <p>So instead you need to use C# to make the camera follow the player using the player objects transform position. This is what I've tried:</p>
  
  <pre><code>public Transform target;
  public float smoothing = 5f;
  
  Vector3 offset;
  
  public GameObject playerPrefab;
  
  private void SpawnPlayer()
  {
      Network.Instantiate(playerPrefab, Vector3.up * 5, Quaternion.identity, 0);
      offset = transform.position - target.position;
  }
  
  void LateUpdate()
  {
      Vector3 targetCamPos = target.position + offset;
      transform.position = Vector3.Lerp(transform.position, targetCamPos, smoothing * Time.deltaTime);
  }
  </code></pre>
  
  <p>Ofcourse I've assigned the player prefab to target. So when the game starts, the cameras position is transformed to the players position. But after that, it refuses to follow the player. It just sits there.</p>
  
  <p>So I've started debugging this with:</p>
  
  <pre><code>Debug.log(target.position);
  </code></pre>
  
  <p>It returns the starting location of the player, but doesn't get updated as the player moves around. It remains the same. So that's obviously the reason the camera won't follow the player.</p>
  
  <p>The question is: Why doesn't the player position get updated? Or most likely it does, but the script doesn't see it. What am I doing wrong?</p>