I just watched the tutorial on toggling components on and off and while successfully toggling an object’s renderer component, I can’t toggle a light’s light component
I used the exact same code as in the tutorial, but it just won’t work…
I just watched the tutorial on toggling components on and off and while successfully toggling an object’s renderer component, I can’t toggle a light’s light component
I used the exact same code as in the tutorial, but it just won’t work…
Is The Script On The Light? If So This Should Work. If Not You Need To Use:
using UnityEngine;
using System.Collections;
public class EnableComponents : MonoBehaviour
{
private Gameobject lightObject;
private Light myLightComponent;
void Start ()
{
lightObject = Gameobject.Find("<Insert Objects Name>")
myLight = lightObject.GetComponent<Light>();
}
void Update ()
{
if(Input.GetKeyUp(KeyCode.Space))
{
myLight.enabled = !myLight.enabled;
}
}
}