Game Controller Help

I have a game consisting of a main menu screen and 2 scenes. In the first scene, the player will be navigating in the first person through a cave-like opaque model.

In the second scene, I want to show an orientation–basically the same model with a semi-transparent material viewed in the third person from outside he model. I also wish to have a blinking orb or something similar to indicate where the player is inside the model.

The user currently can toggle between scenes using a GUI button.

The people on the IRC said it’s best to only use DontDestroyOnLoad on one game object, preferably the game controller. I’ve been trying to create a controller, but I’m really stuck! I need to pass the coordinates of both the model and camera to the game controller, then instantiate the new model and orb in their place. Also, should the player quit to the main menu, I need to destroy all of these objects.

I know there are multiple threads on passing variables between scenes, but I’m running into problems applying that info to meshes in my scene (I’m new to scripting).

Does anyone have any suggestions on how I can do this? Is there a better way than what I’ve thought up?

Thanks

I’d think this would be better with just using one scene. That way switching would be instant, instead of loading in another scene. Sounds like all you have to do is swap the material on your cave model and switch camera modes.

–Eric

Hmmm…this may be better.

If I wanted to have a side and top view for the orientation, is it possible to switch from the FPS “main camera” view to a split screen of two camera vews (side and top) for the orientation?

Can a button be program to switch camera views?

Eric,

I found your post on switching materials: http://forum.unity3d.com/viewtopic.php?t=6198 Which should be excellent!!

I still haven’t got a clue how to program a switch from one camera to another. It seems pretty basic. I must be missing something!?

If your FPS view and your orientation views aren’t on-screen simultaneously, you don’t even have to do that. Just swap the material when the view is changed.

Probably simplest to deactivate the FPS camera/script when not in use, and same for the orientation view. You can have a control script which handles the activating/deactivating.

–Eric

Do you know how to do this? :sweat_smile: Or perhaps point me to some of the documentation that could give me a hint?

Thanks

The basics, which you’d use for the control script (untested forum code warning):

var fpsCam : GameObject;
var orientationCam : GameObject;
var fpsMaterial : Material;
var orientationMaterial : Material;
var caveObject : GameObject;

function Update () {
    if (Input.GetButtonDown("SwitchCameras")) {
        fpsCam.active = !fpsCam.active;
        orientationCam.active = !orientationCam.active;
        if (fpsCam.active) {
            caveObject.renderer.sharedMaterial = fpsMaterial;
        }
        else {
            caveObject.renderer.sharedMaterial = orientationMaterial;
        }
    }
}

Put that on an empty game object, or some other object that’s active at all times. It’s slightly more involved than that, since you’d have to activate/deactivate all objects that need it…presumably the FPS mode has at least a few objects (as per the FPS prefab), and you mentioned using two cameras for the orientation view. But hopefully that gets you headed in the right direction.

–Eric

Thanks so much!! This is a great start–I’ll play around with it!

Eric, I’ve been trying your code out, and when I start, my view is the FPS cam, but it when I push “SwitchCameras” once, no camera is activated (I get a black screen). When I push it again I get the orientation cam, but I can never seem to get it to display the fps cam. The button either toggles between the orientation cam or the black screen.

Maybe it is because both cams are deactivated with:

fpsCam.active = !fpsCam.active;
orientationCam.active = !orientationCam.active;

??? I’ve tried manipulating these, but I still keep getting that black screen!

Does it matter that my FPS cam is the child of an object?

var fpsCam : GameObject; 
var orientationCam : GameObject; 
var fpsMaterial : Material; 
var orientationMaterial : Material; 
var caveObject : GameObject; 



function Update () { 
	
    
    if (Input.GetButtonDown("SwitchCameras")) { 
        fpsCam.active = false; 
        orientationCam.active = true; 
         } 
          else {
        	fpsCam.active = true;
        	orientationCam.active = false;
        }
        if (fpsCam.active) { 
            caveObject.renderer.sharedMaterial = fpsMaterial; 
        } 
        else { 
            caveObject.renderer.sharedMaterial = orientationMaterial; 
        } 
       
        	

}

This code seems to work, but only makes a flash when the button is pressed. This is probably because the “Active” states only occur WHILE the button is being pressed. How could I get them to stay active when the button is pressed, and remain active until it is pressed again? Is that why you used the !??

Sorry for all the questions!
:sweat_smile:

Hmmm… This seems to work!! I made a private var to regulate the switching/material changes when the button is pressed!!!

var fpsCam : GameObject; 
var orientationCam : GameObject; 
var fpsMaterial : Material; 
var orientationMaterial : Material; 
var caveObject : GameObject; 
private var switcher : boolean; 


function Update () { 
	
    if (Input.GetButtonDown("Fire1")) { 
        switcher = !switcher; 
        if (switcher == true) { 
            caveObject.renderer.sharedMaterial = fpsMaterial;
            fpsCam.active = true; 
            orientationCam.active = false;
        } 
        else { 
            caveObject.renderer.sharedMaterial = orientationMaterial; 
             fpsCam.active = false; 
             orientationCam.active = true;
        } 
    } 
}