Multiple lights on/off using a single button in unity? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

12th Oct 2018, 6:22 PM
Zen
Zen - avatar
2 Answers
+ 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...
13th Oct 2018, 6:07 AM
Zen
Zen - avatar
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);          }            }            } 
13th Oct 2018, 1:52 AM
Evan Martine