- Home /
Array Issue
I am trying to make an array of lights and when a specific event happens it turns them all off. I have the array working and if I place a debug statement in the loop for it it will print off just fine.
I cant figure out how to make it turn off all my lights.
using UnityEngine;
using System.Collections;
public class DayNightController : MonoBehaviour
{
public GameObject[] lights;
void Update ()
{
for(int i = 0; i < lights.Length; i++)
{
lights.SetActive (false);
}
}
}
I get this error : error CS1061: Type UnityEngine.GameObject[]' does not contain a definition for
SetActive' and no extension method SetActive' of type
UnityEngine.GameObject[]' could be found (are you missing a using directive or an assembly reference?)
Answer by VesuvianPrime · Sep 12, 2014 at 04:52 PM
Hey Davidflynn2
Please try the following:
lights[i].SetActive(false);
The solution here is that you need to access each item in the array individually.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Using an array instead 2 Answers
How to select adjacent cubes along edges? 2 Answers