Hi,
I have some problems with active or desactive cameras, I have coded a Game Manager for my game, I mean, on my main menu I have two options: Single Player and Cooperative, on the menu I pass an object called gameman with the info about the number of players. And well on the game I have two cameras for the Single Player Game (one near and one far) and 4 camera for cooperative (2 near and 2 far). By default I have enabled cooperative cameras (and listener it’s on near of player1 on cooperative). I have done the following script to remove not usefull cameras, but when I try to use it, my game or unity crashes. What I’m doing wrong?
here you have the variables I have used:
var Player1 : Transform;
var Player2 : Transform;
//Camara
var camaraPersonajeSingle: GameObject;
var camaraPersonajeSingleFar: GameObject;
var camaraPersonajeDoubles1: GameObject;
var camaraPersonajeDoubles2: GameObject;
var camaraPersonajeDoubles1Far: GameObject;
var camaraPersonajeDoubles2Far: GameObject;
Here you have the code:
gameman = GameObject.Find("/TypeOfGameManager").GetComponent(TypeOfGameManager);
//No hay GameManager
if (!gameman) Debug.Log("No hay GameManager");
if (gameman.numeroDePlayers==1){
Player2.GetComponent(ThirdPersonStatus).SendMessage("DestruccionDeObjeto");
camaraPersonajeDoubles1.GetComponent(AudioListener).enabled = false;
//camaraPersonajeDoubles1.active = false;
//camaraPersonajeDoubles2.active = false;
//camaraPersonajeDoubles1Far.active = false;
//camaraPersonajeDoubles2Far.active = false;
//Activamos camaras 1 jugadores
camaraPersonajeSingle.active = true;
camaraPersonajeSingle.GetComponent(AudioListener).enabled = true;
camaraPersonajeSingleFar.active = true;
}
if (gameman.numeroDePlayers==2){
camaraPersonajeSingle.active = false;
camaraPersonajeSingleFar.active = false;
}
If instead of taking GameObject type I take Camera type for the variables Unity crashes instantiantly, If not I get this error
PPtr cast failed when dereferencing! Casting from Camera to GameObject!
UnityEngine.GameObject:set_active(Boolean)
On this Line
camaraPersonajeDoubles1.active = false;