Created
January 9, 2018 22:41
-
-
Save Bubytech/ac4bfb9f3b72dbecb0f20e27ff2c4e07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class CarControl : MonoBehaviour { | |
public GameObject[] Lights_Reverse; | |
public GameObject[] Lights_Norm; | |
public GameObject[] Lights_Turn; | |
public Material[] turn; | |
public Material[] norm; | |
public Material[] reverse; | |
[Space] | |
public AudioSource StartupSound; | |
public AudioSource IdleSound; | |
public AudioSource Blinker; | |
private bool Started = false; | |
public ParticleSystem smoke; | |
public bool turnIsOn; | |
public bool normIsOn; | |
public bool revIsOn; | |
private bool turnIsOnT; | |
public float blinkerTime = 0; | |
void Start(){ | |
turnIsOn = false; | |
normIsOn = false; | |
revIsOn = false; | |
turnIsOnT = false; | |
} | |
public void turnOn(string name){ | |
if (name == "norm") { | |
normIsOn = !normIsOn; | |
} | |
else if (name == "turn") { | |
turnIsOn = !turnIsOn; | |
Blinker.Play (); | |
} | |
else if (name == "reverse") { | |
revIsOn = !revIsOn; | |
} | |
} | |
public void StartUp(){ | |
if (!Started) { | |
StartupSound.Play (); | |
smoke.Play (); | |
Started = true; | |
} else { | |
Started = false; | |
} | |
} | |
private float timer = .5f; | |
void Update(){ | |
if (StartupSound.time > 2) { | |
StartupSound.Stop (); | |
IdleSound.Play (); | |
} | |
if (!Started) | |
IdleSound.Stop (); | |
//turn blink | |
if (turnIsOn) { | |
timer -= Time.deltaTime; | |
if (timer < 0) { | |
if (turnIsOnT) { | |
turnIsOnT = false; | |
} else { | |
turnIsOnT = true; | |
} | |
timer = blinkerTime; | |
} | |
} else { | |
Blinker.Stop (); | |
turnIsOnT = false; | |
} | |
if (!turnIsOnT) { | |
foreach (GameObject go in Lights_Turn) { | |
go.gameObject.GetComponent<Renderer> ().material = turn [1]; | |
} | |
} else { | |
foreach (GameObject go in Lights_Turn) { | |
go.gameObject.GetComponent<Renderer> ().material = turn [0]; | |
} | |
} | |
if (!normIsOn) { | |
foreach (GameObject go in Lights_Norm) { | |
go.gameObject.GetComponent<Renderer> ().material = norm [1]; | |
} | |
} else { | |
foreach (GameObject go in Lights_Norm) { | |
go.gameObject.GetComponent<Renderer> ().material = norm [0]; | |
} | |
} | |
if (!revIsOn) { | |
foreach (GameObject go in Lights_Reverse) { | |
go.gameObject.GetComponent<Renderer> ().material = reverse [1]; | |
} | |
} else { | |
foreach (GameObject go in Lights_Reverse) { | |
go.gameObject.GetComponent<Renderer> ().material = reverse [0]; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment