Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Toggle area light

Discussion in 'Scripting' started by MthemetalD, Oct 19, 2019.

  1. MthemetalD

    MthemetalD

    Joined:
    Jun 28, 2013
    Posts:
    2
    First time using the forums. Very new to unity and dont understand why a bit of code is not working:
    I have a button and a toggle as im learning to use the UI system.
    I have an empty game object with the below script.
    The toggle spotlight method works for both button and toggle but the area light does not work for either.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class UIBehavior : MonoBehaviour
    7. {
    8.     public Light lSpot;
    9.     public Light redLight;
    10.  
    11.     public void ToggleSpotlight()
    12.     {
    13.         lSpot.enabled = !lSpot.enabled;
    14.     }
    15.  
    16.     public void ToggleRedLight()
    17.     {
    18.         redLight.enabled = !redLight.enabled;
    19.     }
    sorry if this is a really beginner question, I've looked over the documents and I cant find any reason why this works for the directional light but not the area light.
     
  2. MthemetalD

    MthemetalD

    Joined:
    Jun 28, 2013
    Posts:
    2
    Ok figured it out. Real beginner mistake: I had the Area Light object turned off in the editor. Can threads be deleted? :p
     
    Kurt-Dekker likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    Always best to leave the thread in place... it very well might help someone else. It has happened to me a lot. That's the beauty of google...