+ 1
Multiple lights on/off using a single button in unity?
anybody here who knows how to switch multiple lights on/off using a ui button in unity?
2 ответов
+ 1
hey there, thank you so much for your time effort and help but can you please tell me how is it going to make my ui button to switch lights on or off? ... i can make logics but i am not a good coder...
0
you just have to put the same tag on all of the light objects and use a for loop to toggle them on/off:
Here is a script:
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
void Start () {
GameObject[] allLights= GameObject.FindGameObjectsWithTag ("myLight");
foreach (GameObject i in allLights){
i.SetActive(false);
}
}
}