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

How to set am object active and deavtic with the new UI toggle?

Discussion in 'UGUI & TextMesh Pro' started by Asta_D, Mar 25, 2015.

  1. Asta_D

    Asta_D

    Joined:
    Oct 16, 2013
    Posts:
    15
    I like the new UI because for me as a designer it makes live much easier.
    But now i want to turn off and on my main light with the UI toggle. By default it is on, and it works to be turned off, but how do i use the new toggle to turn it on again? Do i have to script it?

    I just tried it as an alternative with this script, but it doesn't work:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Sonnenlicht : MonoBehaviour {
    5.  
    6.     private bool SonneAn = true;
    7.  
    8.  
    9.     // Use this for initialization
    10.     void Start () {
    11.  
    12.     }
    13.  
    14.     // Update is called once per frame
    15.     public void SonneAnAus()
    16.     {
    17.         if(SonneAn == true)
    18.         {
    19.             Debug.Log("Sonne aus");
    20.             Debug.Log("Sonne = " + SonneAn);
    21.             this.GetComponent<Light>().intensity = 0;
    22.             SonneAn = false;
    23.         }
    24.         if(SonneAn == false)
    25.         {
    26.             this.GetComponent<Light>().intensity = 1;
    27.             SonneAn = true;
    28.         }
    29.     }
    30. }


    Regards from Germany
    Asta


    I got it. I have to use enable in the toogle's "On vale change"-component.
     
    Last edited: Mar 25, 2015
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,688
    Congrats on getting there @Asta_D , you can hook almost anything up to the UnityEvent hooks in the editor. Or even create your own using the Event Interface handlers.