| | | 1 | | using UnityEngine; |
| | | 2 | | |
| | | 3 | | public class HouseController : MonoBehaviour |
| | | 4 | | { |
| | | 5 | | public GameObject[] windowGlassObjects; |
| | | 6 | | |
| | | 7 | | [ColorUsage(true, true)] |
| | | 8 | | public Color lightsOnEmissionColor; |
| | | 9 | | |
| | | 10 | | [ColorUsage(true, true)] |
| | | 11 | | public Color lightsOffEmissionColor; |
| | | 12 | | |
| | 4 | 13 | | public bool lightStatus = false; |
| | 4 | 14 | | private bool currentLightStatus = false; |
| | | 15 | | public AudioSource switchSound; |
| | | 16 | | |
| | | 17 | | private void Start() |
| | 2 | 18 | | { |
| | 2 | 19 | | changeLights(); |
| | 2 | 20 | | } |
| | | 21 | | |
| | | 22 | | private void Update() |
| | 205 | 23 | | { |
| | 205 | 24 | | if (currentLightStatus != lightStatus) |
| | 0 | 25 | | { |
| | 0 | 26 | | currentLightStatus = lightStatus; |
| | 0 | 27 | | changeLights(); |
| | 0 | 28 | | switchSound.Play(); |
| | 0 | 29 | | } |
| | 205 | 30 | | } |
| | | 31 | | |
| | | 32 | | public void changeLights() |
| | 3 | 33 | | { |
| | 3 | 34 | | Color colorChange = lightsOffEmissionColor; |
| | 3 | 35 | | if (currentLightStatus == true) colorChange = lightsOnEmissionColor; |
| | 33 | 36 | | foreach (GameObject targetObject in windowGlassObjects) |
| | 12 | 37 | | { |
| | 12 | 38 | | Material targetMaterial = targetObject.GetComponent<Renderer>().material; |
| | | 39 | | // Set the new HDR color to the material's emission color property |
| | 12 | 40 | | targetMaterial.SetColor("_EmissionColor", colorChange); |
| | | 41 | | |
| | | 42 | | // Enable emission on the material (if it's not already enabled) |
| | 12 | 43 | | targetMaterial.EnableKeyword("_EMISSION"); |
| | 12 | 44 | | } |
| | 3 | 45 | | } |
| | | 46 | | } |