- Home /
Switching Camera not working
Hi everybody,
I'm having a difficult time coding a switch on two camera's. For some reason I can't get the switch to work properly, perhaps someone can help me out?
Situation: I set up a first person controller and a car controller. They work fine when controlling seperatly. I made a trigger in order for the switching camera (and controllers) to work ingame. When I test this and look at what's going on in Unity's scene view, everything works fine, except the camera is not switching.
I tried two things: When I state that the camera is .active the switch ingame works for one time. When I switch back, all I see is a white screen (while the controller and everything still works). When I state that the camera is .enabled it's not working at all.
I left out some parts that are not involving the camera changing, so here's the (adjusted) script:
var PlayerCamera : Camera;
var CarCamera : Camera;
var isPlayerVisable : boolean = false;
var TextShow : boolean;
function Start ()
{
PlayerCamera.camera.enabled = true;
CarCamera.camera.enabled = false;
}
function Update ()
{
if (Input.GetKeyDown(KeyCode.E) && isPlayerVisable == true)
{
PlayerCamera.camera.enabled = false;
CarCamera.camera.enabled = true;
TextShow = false;
isPlayerVisable = false;
}
else {
if (Input.GetKeyDown(KeyCode.E) && isPlayerVisable == false)
{
CarCamera.camera.enabled = false;
PlayerCamera.camera.enabled = true;
TextShow = true;
isPlayerVisable = true;
}
Answer by DrunkFish01 · Jun 09, 2014 at 12:36 PM
do
var PlayerCamera : GameObject;
var CarCamera : GameObject;
just set the objects on off like
PlayerCamera.SetActive(false);
CarCamera.SetActive(true);
Thanks for your comment ChrisHellas! Unfortunately the code you provided doesn't resolve my problem. The same issue remains.
Your answer
Follow this Question
Related Questions
Switching Between Cameras JavaScript 0 Answers
Switching cameras (JavaScript) 0 Answers
Destroy object question! 3 Answers
Camera switching with iTween Touch 1 Answer
Set Max Rotation On Weapon Sway 0 Answers