- Home /
Switching multiple cameras
Hello all,
This is a question I was able to figure out earlier, but I've thrown a wrench into it and am hoping someone might be able to help me out. I realized that for all the trouble I'm having trying to figure out keeping playerprefs while switching scenes, saving scenes, etc. there is a much simpler solution to my issues: namely, just have different cameras and build my scene that way. That's how I've made my pause menu, and then this morning I made the game's main menu that way. The main menu shows the view of camera 1, pressing a button pushes you out to camera 2. (the actual game menu) For posterity, here's that script, which I'm having no issues with, it works great:
using UnityEngine;
using System.Collections;
public class MainMenuCameraSwitch : MonoBehaviour {
public Camera camera1;
public Camera camera2;
bool camera1ActiveBool;
void Start () {
camera1.camera.active = true;
camera2.camera.active = false;
camera1ActiveBool = true;
}
void Update () {
//use whatever button you want to toggle
if(Input.GetButtonDown("Action")){
if (camera1ActiveBool == true)
{
camera1.camera.active = false;
camera2.camera.active = true;
camera2.enabled = true;
camera1.enabled = false;
//camera1ActiveBool = false;
//Time.timeScale = 0;
}
else if (camera1ActiveBool == false)
{
camera1.camera.active = true;
camera2.camera.active = false;
camera1ActiveBool = true;
Time.timeScale = 1;
}
}
}
}
Again, that camera script works fine. Pushes me from the title screen to the game. Now I want to introduce a logo, or "Splash screen" right before the title screen. No problem, I thought, just plug this script in the same way, disable the menu camera, and allow the script to enable it. No dice, it kicks right from the logo to either a blank screen (never enabling the menu camera) or right to the game. (bypassing the menu camera entirely) Have experimented with unchecking the box in the top left corner of the inspector, checking it, retagging it as a regular camera and tagging the logo camera as main, etc. When that didn't work I thought maybe since I had the script already attached elsewhere that it might have been an issue, so I put a different one on (now having two camera switch scripts) shown here:
var camera1 : Camera;
var camera2 : Camera;
function Start () {
camera1.camera.active = true;
camera2.camera.active = false;
yield WaitForSeconds(4.0);
}
yield WaitForSeconds(4.0);
function Update () {
//camera1.camera.active = false;
// camera2.camera.active = true;
}
Now, yeah, I know that one is a newb fueled disaster. I knew that yield WaitForSeconds could not exist inside update, so tried putting it in a couple of different places, the intention being finally that the splash screen would pop up, appear for four seconds, then that camera would disable and the title menu camera would enable, and then the player could press the action button, which would send them to the game world. It seems that the menu camera is never in fact disabled, as the audio clip attached to it plays, even though the splash screen camera has no audio listener or source. So what essentially happens right now is any of the following, depending on what box I have checked in the upper left corner of the inspector:
Splash screen shows, but music plays Title Screen doesn't show, just black screen__pressing "action" still kicks player to main game camera.
Or
Splash screen doesn't show_Title Screen Shows, music is fine_Kicking to main camera successful with press of action button.
So steps two and three work fine, it's just getting that splash screen to appear for a certain number of seconds that's been the issue. My worry is that maybe having two camera switch scripts on a single camera (actually on a game object, and then the script calls the camera) might be confusing things. Any and all advice is humbly appreciated. Thanks, and God bless.
you simply have to have a routine that carefully turns all cameras OFF< and then turns one ON. it's a program$$anonymous$$g basic
Your answer
Follow this Question
Related Questions
How to set main camera? 3 Answers
Instantiated GuiTextures not showing 1 Answer
camera movement problem? 1 Answer
setting a character controller orientation by script 1 Answer
Switching camera effects 1 Answer