Camera Switch error
Hi,
I trying to make a dialog system inside my objectives but I have a script problem when the script try to change from one camera to another..
in my game I set the objectives to a int value, when we press play start a cutscene with 16 seconds.. the player camera, the dialogue camera, the player canvas with the buttons and the dialogue canvas are disabled by ( gameobject.active = false; ) and all works fine.. after the cutscene the player camera and canvas turn active = true; and the cutscene camera, cutscene canvas, turn false and the dialogue still false.. so far all works..
so the player have to acomplish the first objective turning objective int value from 0 to 1.. in this moment the player camera, player canvas, have to turn false, and the dialogue camera and canvas have to turn true and show in the game scene.. and that is the problem.. the player canvas and camera dont turn false.. and after a seconds the player camera and the dialogue camera start to change from one to another every frame..
I already try a lot of things and dont know how to resolve.. here is the code I using.. I resumed.. have no errors..
void Start (){ (just for fix the visualization)
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class MISSAO5: MonoBehaviour {
int Objective;
float Distance;
GameObject portal;
GameObject PlayerCam;
GameObject CutSceneScreen;
GameObject CutSceneCam;
GameObject LevelScreen;
bool CutScene;
GameObject Avatar1;
GameObject Avatar2;
GameObject Dialog1;
....
GameObject Dialog5;
GameObject DialogScreen;
GameObject DialogCam;
int DialogInt;
void Start (){
portal = GameObject.Find("PORTAL");
PlayerCam = GameObject.Find("ThirdPersonCAM");
CutSceneScreen = GameObject.Find("CUTSCENESCREEN");
CutSceneCam = GameObject.Find("CUTSCENECAM");
LevelScreen = GameObject.FInd("LEVELSCREEN");
Avatar1 = GameObject.Find ("AVATAR1");
Avatar2 = GameObject.Find ("AVATAR2");
Dialog1 = GameObject.Find ("DIALOG1");
....
Dialog5 = GameObject.Find ("DIALOG5");
DialogScreen = GameObject.Find("DIALOGSCREEN");
DialogCam = GameObject.Find("DIALOGCAM")
PlayerCam.active = false;
LevelScreen.active = false;
DialogScreen.active = false;
DialogCam.active = false;
CutScene = false;
}
IEnumerator cutscene()
{
yield return new WaitForSeconds (16);
LevelScreen.active = true;
CutSceneCam.active = false;
CutSceneScreen.active = false;
PlayerCam.active = true;
}
void Update (){
if (CutScene == false) {
StartCoroutine (cutscene ());
}
if (Objective == 0) {
Distance = Mathf.FloorToInt (Vector3.Distance (GameObject.Find ("SNAKE").transform.position, transform.position) / transform.lossyScale.magnitude);
if (Distance <= 1) {
Objective = 1;
}
}
if (Objective == 1) {
Dialogue ();
}
2...3...4..
}
public void Dialogue()
{
PlayerCam.active = false;
DialogCam.active = true;
LevelScreen.active = false;
DialogScreen.active = true;
DialogInt = 1;
if (DialogInt == 1) {
Avatar2.active = false;
Dialog2.active = false;
Dialog3.active = false;
Dialog4.active = false;
Dialog5.active = false;
Avatar1.active = true;
Dialog1.active = true;
2....3....4....5..
}
if (DialogInt == 6) {
PlayerCam.active = true;
DialogCam.active = false;
LevelScreen.active = true;
DialogScreen.active = false;
Objective = 2;
}
}
}
}
Your answer
Follow this Question
Related Questions
Camera Switch Error 2 Answers
Event Trigger Isn't Working. 1 Answer
Menu object not responding 0 Answers
Boolean variable is never true, even if declared true or ticked in the inspector 1 Answer