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. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Question Is it Possible to change the Object given to the "OnClick" event mid runtime?

Discussion in 'Getting Started' started by Nuno1320, Dec 30, 2022.

  1. Nuno1320

    Nuno1320

    Joined:
    Jun 12, 2021
    Posts:
    2
    This is one of my first games and i'm trying to create a Skin Shop, i would to like to know if it is possible to change this object or if i'm going to have to find another way to do this.
    Thanks :)
    upload_2022-12-30_3-28-44.png
     
  2. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    242
  3. tleylan

    tleylan

    Joined:
    Jun 17, 2020
    Posts:
    343
    Additionally let me add that I just about never assign event handlers in the Inspector as per that image. It is not only easy to add them in code (C# coders doesn't typically have a GUI they can assign these handlers to) but it is more flexible. You can conditionally add them if needed, you can change them (as you asked) and you can remove them.
     
    Nuno1320 likes this.
  4. Nuno1320

    Nuno1320

    Joined:
    Jun 12, 2021
    Posts:
    2