Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[HELP] Event System

Discussion in 'UGUI & TextMesh Pro' started by Corvinuz1227, Apr 29, 2015.

  1. Corvinuz1227

    Corvinuz1227

    Joined:
    Mar 2, 2014
    Posts:
    29
    Hi i was trying to use event system, its great but i doing something that i need to set it on a canvas, not in the component itself
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using UnityEngine.EventSystems;
    4. using System.Collections;
    5.  
    6. public class IComponents : MonoBehaviour, IDeselectHandler, ISelectHandler, ISubmitHandler
    7. {
    8.    
    9.     //public Button[] btns;
    10.     //public Slider[] sld;
    11.  
    12.  
    13.  
    14.  
    15.     public void OnDeselect(BaseEventData eventData)
    16.     {
    17.         Debug.Log("OnDeselect" + eventData.selectedObject.GetComponentInChildren<Button>().name);
    18.     }
    19.  
    20.     public void OnSelect(BaseEventData eventData)
    21.     {
    22.         Debug.Log("OnSelect" + eventData.selectedObject.GetComponentInChildren<Button>().name);
    23.     }
    24.  
    25.     public void OnSubmit(BaseEventData eventData)
    26.     {
    27.         Debug.Log("OnSubmit" + eventData.selectedObject.GetComponent<Button>().name);
    28.     }
    29. }
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,685
    Can't do that. Events (when fired) are targetted on the gameObject that the raycast (in the event system) has identified. Can't do global / generic events at present.

    Nothing stopping you creating your own version through :D
     
    Corvinuz1227 likes this.
  3. Corvinuz1227

    Corvinuz1227

    Joined:
    Mar 2, 2014
    Posts:
    29
    Thanks a lot, im kinda newbie and havent code for a long time, need some refreshment hehehe