Question by
SbstnDC · Oct 28, 2016 at 03:03 PM ·
arraylightrandom.range
C# script, light in array randomic
HI,
how can i get array with lights randomic on and off by time.deltatime ?
i got this, but, i need press the key any times
using UnityEngine;
using System.Collections;
public class SystemRandomLights : MonoBehaviour
{
public KeyCode key = KeyCode.A;
public GameObject[] lights;
void Start()
{
lights = GameObject.FindGameObjectsWithTag("Lights");
}
void Update()
{
Debug.Log("KEY");
var onlight = lights[Random.Range(0, lights.Length)];
onlight.SetActive(true);
Debug.Log("light ON \t" + onlight + "\t" + Time.deltaTime);
}
else
{
foreach (GameObject Light in lights)
{
Light.SetActive(false);
Debug.Log("off light all");
}
}
}
}
Comment
first of all, where is the if for the else? Second, I can't see any condition upon which is decided what the light's state should be
Your answer
Follow this Question
Related Questions
how to randomly choose a value from array 3 Answers
How do I use arrays, with getcomponent? 2 Answers
is it possible toggle bool at editor by script? 1 Answer
How to get images from an array visible 0 Answers