I have created a class GameCamera which is basically a unity camera + an integer named “priority”.
I then try to generate an array of the cameras in the scene. But my code does not work.
I get the error : “Object reference not set to an instance of an object”
Here is the code:
import System.Collections.Generic;
class GameCamera
{
var cam : Camera;
var priority : int;
}
class CameraController extends MonoBehaviour {
var mainCameras = GameObject[ ];
var gameCamerasList = new List.();
function Start () {
mainCameras = GameObject.FindGameObjectsWithTag(“MainCamera”);
for ( var i : int= 0; i < mainCameras.Length; i++)
{
var newGameCam : GameCamera;
newGameCam.cam = mainCameras*; ← the error points to this line*
- newGameCam.priority = 1;*
- gameCamerasList.Add(newGameCam);*
- } *
}
I really do not understand what is wrong with this code.
Could someone please give me some help?
Thanks