Quantcast
Channel: Answers by "Kleptomaniac"
Viewing all articles
Browse latest Browse all 90

Answer by Kleptomaniac

$
0
0
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. :P 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 :) That should work, I haven't tested it though :P

Viewing all articles
Browse latest Browse all 90

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>