Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
bobbiannedoerr's avatar
bobbiannedoerr
Honored Guest
10 years ago

2 cameras in a scene issue

I have two cameras in the same scene. One is a 1st person and the one is 3rd person. I am trying to make it be like Resident Evil, where if you went through a door, the player will view a room through a different camera. I have a script for this and there is box collider set to a trigger for that activates the cameras to switch. This works fine unit I add on the OVR scripts and then everything becomes a mess. The camera switch script does not work and you can only "see" through one camera throughout the scene. Help.

8 Replies

Replies have been turned off for this discussion
  • This is possible, and should not be a problem.

    I believe you just have to deactivate the main camera, and then activate whatever other camera you want. At least that is how it works with Unity 5 native VR support. If you are using the Unity 4 integration it may be different.
  • So here is the code I have for the camera switch. Is there something wrong with that?

    #pragma strict

    var cam1 : Camera;
    var cam2 : Camera;

    private var walkedIn : boolean = false;

    function Start()
    {
    cam1.GetComponent.<Camera>().enabled = true;
    cam2.GetComponent.<Camera>().enabled = false;
    }

    function OnTriggerEnter(Col : Collider)
    {
    if(Col.tag == "Player")
    {
    walkedIn = !walkedIn;
    }
    }

    function Update()
    {
    if(walkedIn == true)
    {
    cam1.GetComponent.<Camera>().enabled = false;
    cam2.GetComponent.<Camera>().enabled = true;
    }

    if(walkedIn == false)
    {
    cam1.GetComponent.<Camera>().enabled = true;
    cam2.GetComponent.<Camera>().enabled = false;
    }
    }
  • I believe the function call you want to use is this:

    cam1.gameObject.SetActive(false);
    cam2.gameObject.SetActive(true);
  • If you have an OVRManager script, watch out that you're not disabling and enabling that as you switch cameras (since it's attached to the OVRCameraRig or player controller by default).
  • Yeah, that is exactly the problem. VR only shows on one camera. So the code I have is not working at all. I keep messing with the code but nothing works. Any ideas would be greatly appreciated. Thanks!
  • That code you posted looks funky. Especially that you are switching the cameras in an update function and the cameras are hard-coded. For example. if you had that script on two triggers, it would never work (both would run constantly and whichever ran last would take control).
  • I watched some tutorials and came up with this. I am a beginning coder so I just don't know what else to try and have tried everything I can think of. Can you help me?
  • For only the specific problem I mentioned:

    1. Move the OVRManager component to a new GameObject at the root of your hierarchy (i.e. don't make it a child of any other GameObject). You can probably just drag the component to the new GameObject, but if not, right-click and check for Copy Component/Paste as New Component.

    2. Remove any OVRManager components from your OVRCameraRigs/PlayerControllers

    If you're not using the Oculus Unity Integration or Oculus Tools prefabs, you won't have any OVRManager components and this doesn't apply to you.