0
\$\begingroup\$

I have strange thing here in my script. In this script clock_time turn active lamp object one by one. Where Lamp object turn off after 3 seconds be anther script. If clock time reach 120 or higher again lamp turn active !! Also, light_timer keep counting if lamp is active ??

 public GameObject[] lights; // 3 lamps
public int number;
public int[] light_timer; // 3 values "2,4,6"
public int clock_timer;

void Start()
{
    // all gameObject "lamps" is off
    number = lights.Length -1;


}
void Update()
{
    if (gameObject.activeInHierarchy == true)
    {
        clock_timer = (int)Time.time;
    }
    else
    {
        clock_timer = 0;
    }
    for (int i = 0; i < lights.Length; i++)
    {

        if (clock_timer >= light_timer[i] && lights[i].activeInHierarchy == false)
        {
            lights[i].SetActive(true);
        }

        if (lights[i].activeInHierarchy == true)
        {
            light_timer[i] = light_timer[i] + 1;
            print("me : " + i);
        }

    }

}
\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

I solved. It's my mistake. All what i have to do is...

  for (int i = 0; i < lights.Length; i++)
    {

        if (clock_timer == light_timer[i] && lights[i].activeInHierarchy == false)
        {
            lights[i].SetActive(true);
        }

    }

Anyway,Thank you..^-^'..

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .