Search Unity

I need help to call my camera target

Discussion in 'Scripting' started by Yann14, Oct 19, 2018.

  1. Yann14

    Yann14

    Joined:
    Oct 18, 2018
    Posts:
    4
    Hello,

    I'm trying to change the target of my main camera to set it on the instanciated player. So i did this :

    private Camera2DFollow cam;

    then in a private void awake :

    cam = Camera.main.GetComponent<Camera2DFollow>();

    And after, in the private void Instantiate player() :

    cam.target = playerInstantiate;

    But unity says the reference is not set to an instance of an object...

    Where am I wrong ?
     
  2. wtrebella

    wtrebella

    Joined:
    Mar 18, 2013
    Posts:
    35
    Are you sure the Camera2DFollow component is on your main Camera object?