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. Dismiss Notice

Is it possible to assign Action to a button?

Discussion in 'Scripting' started by Abdo023, Nov 7, 2021.

  1. Abdo023

    Abdo023

    Joined:
    Dec 18, 2017
    Posts:
    64
    I have a script like this:

    Code (CSharp):
    1. public class GameEvents : MonoBehaviour
    2. {
    3.     public Action OnSomethingHappens;
    4. }
    When I try to add that action to a UI Button it doesn't show on the menu. Is it not supposed to be done like that?!
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
  3. Abdo023

    Abdo023

    Joined:
    Dec 18, 2017
    Posts:
    64
    Thanks, but no. I'm familiar with unity events.
    I use the Observer Pattern in my project and I rely mostly on Actions for communication between scripts instead of Singletons. It was just weird to notice that it can't be assigned from the inspector.
     
    Last edited: Nov 8, 2021
  4. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,593
    Abdo023 likes this.