So they all start out in the off state then light up as the ball rolls over the switches below them. I have two scripts, one called Rollover.
This is attached to one of the four triggers and animates the switch, lights or dims the light above it, sets a lightOn boolean and passes this information to another script called TimeLightsFeature...
-----------------------
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RollOver : MonoBehaviour
{
[SerializeField] public Animator rolloverAnimator;
public Material[] lightMaterials;
public Renderer lightRenderer;
public bool lightOn = false;
public int thisLightNumber;
private TimeLightsFeature timeLightsFeature;
void Awake()
{
timeLightsFeature = GameObject.FindObjectOfType<TimeLightsFeature>();
}
void Start()
{
lightRenderer.enabled = true;
if (lightOn == false)
{
lightRenderer.sharedMaterial = lightMaterials[0];
}
}
private void OnTriggerEnter(Collider other)
{
rolloverAnimator.SetBool("RolloverDown",true);
if (lightOn == false)
{
lightRenderer.sharedMaterial = lightMaterials[1];
lightOn = true;
timeLightsFeature.UpdateLightArray(thisLightNumber, true);
return;
}
else if (lightOn == true)
{
lightRenderer.sharedMaterial = lightMaterials[0];
lightOn = false;
timeLightsFeature.UpdateLightArray(thisLightNumber, false);
return;
}
}
private void OnTriggerExit(Collider other)
{
rolloverAnimator.SetBool("RolloverDown", false);
}
}
-------------------
TimeLightsFeature currently only has this in it...
---------------------
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TimeLightsFeature : MonoBehaviour
{
bool allTrue = false;
[SerializeField] bool[] isTimeLightLit;
public void UpdateLightArray(int lightNumber, bool isLit)
{
isTimeLightLit[lightNumber] = isLit;
}
}
----------------------
I'm not sure the best way to structure this or even if I should be using lists instead of arrays to get the booleans to shift left and right.
Any help would be appreciated.