In the first script:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LightsEffects : MonoBehaviour
{
public enum Directions
{
Forward, Backward
};
private Renderer[] renderers;
private float lastChangeTime;
private int greenIndex = 0;
public void LightsEffect(List<GameObject> objects, Color instantiateColor, Color colorEffect)
{
renderers = new Renderer[objects.Count];
for (int i = 0; i < renderers.Length; i++)
{
renderers[i] = objects[i].GetComponent<Renderer>();
renderers[i].material.color = Color.red;
}
// Set green color to the first one
greenIndex = 0;
renderers[greenIndex].material.color = Color.green;
}
public void LightsEffectCore(float delay, bool changeDirection)
{
// Change color each `delay` seconds
if (Time.time > lastChangeTime + delay)
{
lastChangeTime = Time.time;
// Set color of the last renderer to red
// and the color of the current one to green
renderers[greenIndex].material.color = Color.red;
if (changeDirection == true)
{
Array.Reverse(renderers);
changeDirection = false;
}
greenIndex = (greenIndex + 1) % renderers.Length;
renderers[greenIndex].material.color = Color.green;
}
}
}
In this script i want to use the enum Directions instead the bool in the core method:
public void LightsEffectCore(float delay, bool changeDirection)
Instead bool changeDirection to use the enum to decide what direction Forward or Backward.
And then to use this script in another one for example in another script i did:
public LightsEffects lightseffect;
Then in Start:
void Start()
{
lightseffect.LightsEffect(objects, Color.red, Color.green);
}
Then in Update i want to decide the direction:
void Update()
{
lightseffect.LightsEffectCore(0.1f, false);
}
But instead false/true i want to use also here Forward/Backward Maybe something like:
lightseffect.LightsEffectCore(0.1f, lightseffect.Forward);
Since false/true not really have a meaning of what it's doing.
Another option is to leave it with false/true but to add a description to the method when the user typing: lightseffect.LightsEffectCore(
When he type ( he will see a description of what the method do and when he will type , It will tell him what the false/true will do. But i'm not sure how to make a description for that.