Created
August 24, 2020 14:35
-
-
Save seferciogluecce/3090e25af5673f3a93fa7ddace35dc37 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.Generic; | |
using UnityEngine; | |
using Random = UnityEngine.Random; | |
public enum SwitchHighlightMode | |
{ | |
Random, | |
InOrder //Loop | |
} | |
public class RandomHighlight : MonoBehaviour | |
{ | |
public Material HighlightOnMaterial; | |
public Material HighlightOffMaterial; | |
public SwitchHighlightMode HighlightMode; | |
private List<Renderer> Switches; | |
private int switchCount; | |
private int CurrentHighlightedSwitchId = 0; | |
private float NextHighlightDuration = 0.8f; | |
private void Start() | |
{ | |
SetSwitches(transform); //1 | |
} | |
public void SetSwitches(Transform SwitchParent) | |
{ | |
Switches = new List<Renderer>(); | |
switchCount = SwitchParent.childCount; | |
for (int i = 0; i <switchCount; i++) | |
{ | |
Switches.Add(SwitchParent.GetChild(i).GetComponent<Renderer>()); | |
Switches[i].material = HighlightOffMaterial; | |
} | |
ChangeTheHighlightedSwitch(); | |
} | |
void ChangeTheHighlightedSwitch() | |
{ | |
Switches[CurrentHighlightedSwitchId].material = HighlightOffMaterial; | |
switch (HighlightMode) | |
{ | |
case SwitchHighlightMode.InOrder: | |
CurrentHighlightedSwitchId = (CurrentHighlightedSwitchId + 1) % switchCount; | |
break; | |
case SwitchHighlightMode.Random: | |
CurrentHighlightedSwitchId = Random.Range(0, switchCount); | |
break; | |
} | |
Switches[CurrentHighlightedSwitchId].material = HighlightOnMaterial; | |
Invoke("ChangeTheHighlightedSwitch", NextHighlightDuration); | |
// Invoke("ChangeTheSource",Random.Range(nextMinDur,nextMaxDur)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment