Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

getter function as variable

Discussion in 'Scripting' started by Roni_Person, Dec 22, 2019.

  1. Roni_Person

    Roni_Person

    Joined:
    Sep 24, 2019
    Posts:
    45
    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:
    113
    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. Roni_Person

    Roni_Person

    Joined:
    Sep 24, 2019
    Posts:
    45
    No i am not the same person as yesterday
     
  4. craig4android

    craig4android

    Joined:
    May 8, 2019
    Posts:
    113
    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. Roni_Person

    Roni_Person

    Joined:
    Sep 24, 2019
    Posts:
    45
    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:
    113
    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. Roni_Person

    Roni_Person

    Joined:
    Sep 24, 2019
    Posts:
    45
    Hm...
    It sadly not works with return values :(
     
unityunity