Search Unity

Reference name of Toggle

Discussion in 'Scripting' started by eco_bach, Mar 14, 2020.

  1. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    I have a class extending Toggle and I imply need to reference the name of that Toggle as used in the editor
    Most of the answers from a google search assume you are dynamically instantiating the Toggle. I am not.

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.Linq;
    5.  
    6.  
    7. public class PointerDownToggle : Toggle {
    8.      
    9.     public override void OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData)
    10.     {
    11.     }
    12.  
    13.     public override void OnPointerDown (UnityEngine.EventSystems.PointerEventData eventData)
    14.     {
    15.         base.OnPointerClick (eventData);
    16.  
    17.         group.NotifyToggleOn(this);
    18.  
    19. //doesn't work since Toggle doesn't extend Monobehavior!
    20.         Debug.Log("ASSERT  this.name = "+ this.name);
    21.     }
    22.  
    23. }
    24.  
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Check out .GetType()... I think that gives you what you want:

    Code (csharp):
    1. Debug.Log( GetType() + ".OnPointerDown();");
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Be advised that Toggle does in fact extend Monobehavior, just through a few other types.