0

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.

3
  • I see now that if i add in the first script above the method a summary: /// <summary> /// Returns testing. /// </summary> it will give description to the method. And how do i add a summary to specific parameter for example the false/true ? Commented Nov 21, 2017 at 16:30
  • Ok param name is for specific parameter for example: /// <param name="changeDirection">Changing the lights movement directions - false = forward, true = backward.</param> Commented Nov 21, 2017 at 16:33
  • I guess i will stay with that way instead using enum Commented Nov 21, 2017 at 16:34

1 Answer 1

1

Directions is the name of the enum you're interested in. It's also contained within the LightsEffects class.

Thus the way to reference it somewhere else would be LightsEffects.Directions and then another dot and then the value (Forward,etc). This is similar to a Fully Qualified Name, but with part of that scope already declared (whatever import/using that gets you LightsEffects).

So your line:

lightseffect.LightsEffectCore(0.1f, lightseffect.Forward);

Becomes:

lightseffect.LightsEffectCore(0.1f, LightsEffects.Directions.Forward);

Depending on your IDE, it should even be able to resolve this for you if you had used Directions.Forward: your IDE would have noticed the error (unknown reference Directions) and suggested a fix (change to LightsEffects.Directions), I know that Visual Studio does this, as I have a similar case in a project I'm working on now.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.