Light on/off with UI buttons
First of all we need some setup to perform this task.You add some objects
1.one Plane
2.one Cube
3.Directional light color is dark like night scene.
4.Spot light on cube.Check setup on image
5.add this script to main camera
...................................................................................................................................................................
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Light : MonoBehaviour {
public Light myLight;
// Use this for initialization
void Start () {
}
// Update is called once per frame
public void Light () {
{
myLight.enabled = !myLight.enabled;
}
}
}
...................................................................................................................................................................
6.We need one button that use as a switch.Go to UI and add button and button name is light on/off.
7.Click on button go to click section and add main camera object.
8.Select public function light.
9.Light is working properly.
0 Comments