Search Unity

getter function as variable

Discussion in 'Scripting' started by Deleted User, Dec 22, 2019.

  1. Deleted User

    Deleted User

    Guest

    Hi,
    i want to create a script which i add to a textmesh pro.
    The script should load a value from a script which is attached to a dont destroy on load gameObject as value of the text.
    I have a data script with the function getScore

    public int getScore()


    In my script i want to store the function so that i could change the function in inspector.
    I came over delegates but i dont find anything about Serializable delegates and delegates with return value.

    How can i do this in c#? Thx
     
  2. craig4android

    craig4android

    Joined:
    May 8, 2019
    Posts:
    124
    well still not getting your problem (if you are the same person as yesterday) maybe just post all of your code and I'll fix it for you, because the whole design pattern sounds weird
     
  3. Deleted User

    Deleted User

    Guest

    No i am not the same person as yesterday
     
  4. craig4android

    craig4android

    Joined:
    May 8, 2019
    Posts:
    124
    nvm yesterday someone asked a similar question, but you have to provide your code, because like this I cant help you
     
    Last edited: Dec 22, 2019
  5. Deleted User

    Deleted User

    Guest

    I want a function selection like this of the button module for my own script.

    onClick.png

    I want to know how to create such a variable and how to use the selected function in code and get the return value of it.

    I hope it is better to understand what i am looking for now. :)
     
  6. craig4android

    craig4android

    Joined:
    May 8, 2019
    Posts:
    124
    Code (CSharp):
    1. public class Button : MonoBehaviour, Clickable
    2. {
    3.     public UnityEngine.Events.UnityEvent action;
    4.  
    5.     public bool clicked(Vector3 pos)
    6.     {
    7.         action.Invoke();
    8.         return true;
    9.     }
    10. }
    you are welcome
     
  7. Deleted User

    Deleted User

    Guest

    Hm...
    It sadly not works with return values :(