Alternating lights

Hello,

So I have eight lights, what I’m trying to do is have two of them already lit as the game starts.

When one is touched, it and the 2 beside it start to flicker and then switch to the opposite of what they were.

The lights will be placed in a circle/square formation.

I have two scripts right now, one attached to the cylinders that I have over the spot light assets I have which switches colours and the other as the light manager(game manager).

What I’m not sure how to do is making when one is touched, it and the 2 beside it start ti flicker and then switch to the opposite of what they were.

public class LightScript : MonoBehaviour
{
    public int LightIndex;

    [SerializeField] private LightController lightCon;
    [SerializeField] private Color defaultColour;
    [SerializeField] private Color highlightColour;
    [SerializeField] private float resetDelay = 3f;

    // Start is called before the first frame update
    void Start()
    {
        ResetButton();
    }

    private void OnMouseDown()
    {
        Debug.Log("Mouse Clicked");
        PressButton();
    }

    public void PressButton()
    {
        GetComponent<MeshRenderer>().material.color = highlightColour;
        Invoke("ResetButton", resetDelay);
    }

    void ResetButton()
    {
        GetComponent<MeshRenderer>().material.color = defaultColour;
    }
}

Hey there!

well, you need an Array of the Light you have, or maybe a List if “Runtime” you want to add lights, otherwise just stick to array,

whenever you touch a light, you need to get its Index, and therefore, you can calculate up or down to the opposit lights(as long as you know their position) you can do that easly,

in case you have to find out , which lights are the closest ones, and then get the opposit ones, it gets more complicated, depending on wether you want to add lights runtime or not and if you know which index ea. one have or not

1 Like