using UnityEngine;
using System.Collections;
public class DoorControl : MonoBehaviour {
public bool toggleDoor = false;
private bool doorOpen = false;
private const string strOpen = "Open";
private const string strClose = "Close";
public TextMesh counterTM;
private int counter = 0;
public Light redLight;
public Light blueLight;
public Light greenLight;
public Light orangeLight;
public int currentCycleState = NONE;
public float nextCycleTime = 0f;
public bool enableCyclingOfLights = false;
//public int countTo4 = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if ( enableCyclingOfLights )
{
if ( nextCycleTime < Time.time )
{
CycleEachLight();
}
}
else if (toggleDoor)
{
doorOpen = !doorOpen;
if (doorOpen)
{
animation.Play(strOpen);
counter++;
counterTM.text = counter.ToString ();
// when door is opened and the counter changes
// check if the lights need to be changed
UpdateLightsStates( counter );
}
else
{
animation.Play(strClose);
counterTM.text = "Closing Door";
}
toggleDoor = false;
}
}
void CycleEachLight()
{
switch ( currentCycleState )
{
case NONE:
SwitchLightOn ( RED );
currentCycleState = RED;
nextCycleTime = Time.time + 2f;
break;
case RED:
SwitchLightOn ( ORANGE );
currentCycleState = ORANGE;
nextCycleTime = Time.time + 2f;
break;
case ORANGE:
SwitchLightOn ( GREEN );
currentCycleState = GREEN;
nextCycleTime = Time.time + 2f;
break;
case GREEN:
SwitchLightOn ( BLUE );
currentCycleState = BLUE;
nextCycleTime = Time.time + 2f;
break;
case BLUE:
currentCycleState = NONE;
enableCyclingOfLights = false;
counter = 0;
break;
}
}
void UpdateLightsStates ( int count )
{
switch ( count )
{
case 2:
SwitchLightOn ( RED );
break;
case 4:
SwitchLightOn ( ORANGE );
break;
case 7:
SwitchLightOn ( GREEN );
break;
case 9:
SwitchLightOn ( BLUE );
break;
case 10:
enableCyclingOfLights = true;
break;
}
}
private const int NONE = 0;
private const int RED = 1;
private const int ORANGE = 2;
private const int GREEN = 3;
private const int BLUE = 4;
void SwitchLightOn( int lightToSwitchOn )
{
switch ( lightToSwitchOn )
{
case RED:
redLight.enabled = true;
orangeLight.enabled = false;
greenLight.enabled = false;
blueLight.enabled = false;
break;
case ORANGE:
orangeLight.enabled = true;
redLight.enabled = false;
greenLight.enabled = false;
blueLight.enabled = false;
break;
case GREEN:
greenLight.enabled = true;
orangeLight.enabled = false;
redLight.enabled = false;
blueLight.enabled = false;
break;
case BLUE:
blueLight.enabled = true;
greenLight.enabled = false;
orangeLight.enabled = false;
redLight.enabled = false;
break;
default:
//catch all condition
blueLight.enabled = false;
greenLight.enabled = false;
orangeLight.enabled = false;
redLight.enabled = false;
break;
}
}
}
Here is some code Toop and I were thinking of using to make the scene change colour. When you hit the plant, it will make everything that colour.
No comments:
Post a Comment