Skip to main content
New Participant
December 2, 2015

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.
    This topic has been closed for replies.

    8 replies

    Inspiring
    December 2, 2015
    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.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    New Participant
    December 2, 2015
    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;
    }
    }
    Inspiring
    December 2, 2015
    I believe the function call you want to use is this:

    cam1.gameObject.SetActive(false);
    cam2.gameObject.SetActive(true);
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    Inspiring
    December 4, 2015
    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).
    Scorched Battalion - VR Jam edition available for Gear VR and DK2 (Win/Mac/Linux) Jungle Juice Sven Co-op
    New Participant
    December 15, 2015
    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!
    Inspiring
    December 15, 2015
    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).
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    New Participant
    December 15, 2015
    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?
    Inspiring
    December 16, 2015
    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.
    Scorched Battalion - VR Jam edition available for Gear VR and DK2 (Win/Mac/Linux) Jungle Juice Sven Co-op