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;

}

}

}

}

So you have this-

 IEnumerator cutscene()
 {
     yield return new WaitForSeconds (16);
     LevelScreen.active = true;
     CutSceneCam.active = false;
     CutSceneScreen.active = false;
     PlayerCam.active = true;
 }

Which gets called here-

void  Update (){
     if (CutScene == false) {
         StartCoroutine (cutscene ());
     }

But if you look through your code… you never set CutScene = true. So it will keep calling Cutscene over and over and over. You might want to modify your function to read like this:

IEnumerator cutscene()
  {
      yield return new WaitForSeconds (16);
      LevelScreen.active = true;
      CutSceneCam.active = false;
      CutSceneScreen.active = false;
      PlayerCam.active = true;
      
      CutScene = true;
  }

Hi

In this part

if (Objective == 1) {
Dialogue ();
}
2…3…4…

The same as objective == 0
The objective int increase the value to chamge the task that the player have to do…

And this part

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…

The same as the dialogint == 1 the value increase and dialog1 become false and dialog2 become true to change the showing text… i put the 2…3…4…5… to not repeat the same things…

All problem happens when objective become = 1 and call the dialogue function that have to desactive the player camera And the level screen but the game dont do that… the level screen remains active and the player cam too…