I have 3 characters in the scene - C1, C2, and C3. When the player presses the number 1 on the keyboard, I want C2 and C3 to be disabled, while C1 is set to be enabled. And when the player presses 2, I want C1 and C3 to be disabled while C2 is set to be enabled. All 3 characters are generated and created accordingly by scripting when the scene is loaded (They are custom characters defined by the user). Right now, this is what the script looks like:
var Character1 : GameObject;
var Character2 : GameObject;
var Character3 : GameObject;
function Update()
{
if(Input.GetKeyDown(KeyCode.Alpha1))
{
Character1 = GameObject.Find("C1");
//Code for enabling/disabling characters goes here
}
if(Input.GetKeyDown(KeyCode.Alpha2))
{
Character2 = GameObject.Find("C2");
//Code for enabling/disabling characters goes here
}
if(Input.GetKeyDown(KeyCode.Alpha3))
{
Character3 = GameObject.Find("C3");
//Code for enabling/disabling characters goes here
}
}
The problem is, I don't know how to tell it to disable and enable the right ones. The script is attached to an empty GameObject called Character Controller. Any ideas on how I might tell it to disable, for instance, C2 and C3 but enable C1 if 1 is pressed? All the characters have multiple children, so they must be disabled as well. I am fairly new to JavaScript and am trying to learn how this works. Thank you!