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

Question Get data from Button ( OnClick )

Discussion in 'Scripting' started by DK_Kalach, Sep 25, 2023.

  1. DK_Kalach

    DK_Kalach

    Joined:
    Sep 2, 2021
    Posts:
    13
    Have canvas, Some Gameobjects which have buttons
    Now I have 3 levels and in each of them there's an option to manually enter an int ( For the level number )
    What I want is to grab this int ( or any other Input ) and do something with this value ( OnStart , Not onclick event ) for example lower the opacity if I cannot play this level yet, Is there a way to do that? I tried
    Code (CSharp):
    1. GetComponent<Button>().onClick...)
    But I didn't find anything

    Thanks for the help
     

    Attached Files:

  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,862
    Just write a component that stores this information and responds to it accordingly. This kind of information shouldn't be stored in a Unity event.

    Remember, Unity is component based, so you can always just write small components to do whatever you need.
     
  3. DK_Kalach

    DK_Kalach

    Joined:
    Sep 2, 2021
    Posts:
    13
    Good to know
    Gotcha, Thanks