Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Scritpadle Object evoking script on scene

Discussion in 'Scripting' started by mixteraks, May 12, 2024.

  1. mixteraks

    mixteraks

    Joined:
    Aug 1, 2020
    Posts:
    2
    Hi!
    I working on ring menu based on Scriptable Object and I have a problem with evoking functions from scene obiect (example change color of cube). That is a tool so I don't want had a function of changing inside.

    That my Menu Element function
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [CreateAssetMenu(fileName = "NewElement", menuName = "RingMenu/Element", order = 2)]
    4. public class RadialMenuElement : ScriptableObject
    5. {
    6.     public Sprite icon;
    7.     public RadialMenuRing nextRing;
    8.     [Space(20)] public UnityEngine.Events.UnityEvent interactionWhenChoose;
    9.  
    10.     protected virtual void Interact()
    11.     {
    12.         if (interactionWhenChoose != null)
    13.         {
    14.             interactionWhenChoose.Invoke();
    15.         }
    16.     }
    17.  
    18.     public void GiveAMessage(string message)
    19.     {
    20.         Debug.Log(message);
    21.     }
    22. }
    23.  
    Can help me somebody, or say how that can work?
    thanks in advance for help.
     

    Attached Files:

  2. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,936
    What functions are you trying to invoke in the RadialMenuElement?
    RadialMenuElement is a ScriptableObject so you can't use "Invoke" to call methods in or from a ScriptableObject.

    Interact() is not public so you can't call that.

    I think that RadialMenuElement should derive from MonoBehaviour, not ScriptableObject.
     
    Last edited: May 12, 2024
  3. mixteraks

    mixteraks

    Joined:
    Aug 1, 2020
    Posts:
    2
    Maybe I bad present that.
    Element is a element of ring. Rings has array of elements. If you select element ring can change to next ring or invoke the function. Hence UnityEngine.Events.UnityEvent. I try invoke function from cube from UnityEvent in Scriptable Obiect. If you select element 'red' of ring 'cube color change' cube trigger own function and change color.
     

    Attached Files:

  4. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,936
    I guess I don't understand why you're trying to make RadialMenuElement a ScriptableObject.

    How are you going to configure the interactionWhenChoose UnityEvent?
    You can't set up this event in a scriptable object asset.
    I would think RadialMenuElement should derive from MonoBehaviour. You add a RadialMenuElement to each ring button in the inspector. Then you configure the interactionWhenChoose UnityEvent in the inspector window.