Hi Guys,
i have a LevelController script which is loading some data and then instantiates the Objects. As you can see, right after i instantiate my player Prefab, i tell my Camera about it, so my Camera is able to follow my player.
Problem is: The CameraController Scripts tells me, that there is no reference.
Setting Camera, player Gameobject and Camera ControllerScript in my LevelController which builds the Level (and so instantiates my player)
public Camera cami;
private CameraController cc;
private GameObject go_player;
cc = cami.GetComponent<CameraController>();
Later i do the instantiation and tell my Camera who the player is:
case 3:
go_player = Instantiate(Player_PreFab, position, Quaternion.identity) as GameObject;
cc.setTarget(go_player); // <----- I am telling my Camera about the player Gameobject
Then, in my CameraController i have the “setTarget” function i addressed above:
public void setTarget(GameObject go)
{
Debug.Log ("this function has been called");
target = go;
Debug.Log(go.transform.position);
}
Due to the Debug.Log i can see, that the function has been called, but right after that i receive this:
> NullReferenceException: Object
> reference not set to an instance of an
> object CameraController.setTarget
> (UnityEngine.GameObject go) (at
> Assets/Scripts/CameraController.cs:24)
> LevelController.GenerateTiles (Int32
> height, Int32 width) (at
> Assets/Scripts/LevelController.cs:56)
For me that sounds like: The instantiated GameObject player is not known by my cameraController. But, i gave the Gameobject player to the CameraController right after its instantiation.
Any help would be highly appreciated.
KIM