Is it possible to have multiple first person controllers?

Hi again,

I have looked all over but can’t find an answer to my question. Is it possible to have multiple first person controllers? I’m making a visualisation of the Colosseum and I need a few different perspectives but instead of static cameras I wanted to be able to change between each controller and be able to walk around, is this possible? I also wanted the camera changes to be by selecting buttons on the GUI and those buttons also reveal some information in a text box below. I’m very new at scripting and only have a little bit working.

Thanks

This is easy to implement.

Add all your FPC’s to a built in GameObject array in the inspector: public GameObject[] charInst;. Depending on how you want your GUI button layout to be, you can link an individual button to each array element (first person controller). I would suggest just having two buttons to cycle through the array and enable the next controller and disable the previous controller like so:

public GameObject[] charInst;
int selectedChar = 0;
    
void Start () {
    
	foreach (Transform char in charInst) {
	    char.enabled = false;
	}
    charInst[selectedChar].enabled = true;
}
    
void OnGUI () {
    
    if (GUI.Button(new Rect(10, 10, 10, 10), "Next") {
    	charInst[selectedChar].enabled = false;
    	selectedChar++;
    	
		if (selectedChar >= charInst.Length) {
    		selectedChar = 0;
    	}
    	
		charInst[selectedChar].enabled = true;
    }
    
    if (GUI.Button(new Rect(30, 10, 10, 10), "Previous") {
    	charInst[selectedChar].enabled = false;
    	selectedChar--;
    
		if (selectedChar < 0) {
    		selectedChar = charInst.Length - 1;
    	}
    	
		charInst[selectedChar].enabled = true;
    }
}

You may need to change the position and size values of the buttons. I haven’t tested this so there may be some bugs. :stuck_out_tongue:

Hope this helps,

Klep


EDIT:

Here is the Javascript version of my current script:

var charInst : GameObject[];
var selectedChar : int = 0;

function Start () {

    foreach (var char : Transform in charInst) {
        char.enabled = false;
    }
    charInst[selectedChar].enabled = true;
}

function OnGUI () {

    if (GUI.Button(Rect(10, 10, 10, 10), "Next") {
        charInst[selectedChar].enabled = false;
        selectedChar++;

        if (selectedChar >= charInst.Length) {
            selectedChar = 0;
        }

        charInst[selectedChar].enabled = true;
    }

    if (GUI.Button(Rect(30, 10, 10, 10), "Previous") {
        charInst[selectedChar].enabled = false;
        selectedChar--;

        if (selectedChar < 0) {
            selectedChar = charInst.Length - 1;
        }

        charInst[selectedChar].enabled = true;
    }
}

There we go :slight_smile: That should work, I haven’t tested it though :stuck_out_tongue: