Game Development Reference
In-Depth Information
if(theRedKey)
theRedKey.renderer.enabled = false;
if(theBlueKey)
theBlueKey.renderer.enabled = false;
if(theYellowKey)
theYellowKey.renderer.enabled = false;
if(theGreenKey)
theGreenKey.renderer.enabled = false;
if(theWrench)
theWrench.renderer.enabled = false;
}
function Update()
{
if(Input.GetKeyDown("1") && theRedKey)
{
ResetKeys();
theRedKey.renderer.enabled = true;
}
else if (Input.GetKeyDown("2") && theBlueKey)
{
ResetKeys();
theBlueKey.renderer.enabled = true;
}
else if (Input.GetKeyDown("3") && theYellowKey)
{
ResetKeys();
theYellowKey.renderer.enabled = true;
}
else if (Input.GetKeyDown("4") && theGreenKey)
{
ResetKeys();
theGreenKey.renderer.enabled = true;
}
else if (Input.GetKeyDown("5") && theWrench)
{
ResetKeys();
theWrench.renderer.enabled = true;
}
}
Step 31. In the preceding code, note how the objects must be
tested to exist before they can be made visible or invisible. Trying
to make a null game object invisible will throw an error. Before
testing, you will need to assign the wrench object to the script
Search Nedrilad ::




Custom Search