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
using UnityEngine;
[CreateAssetMenu(fileName = "NewElement", menuName = "RingMenu/Element", order = 2)]
public class RadialMenuElement : ScriptableObject
{
public Sprite icon;
public RadialMenuRing nextRing;
[Space(20)] public UnityEngine.Events.UnityEvent interactionWhenChoose;
protected virtual void Interact()
{
if (interactionWhenChoose != null)
{
interactionWhenChoose.Invoke();
}
}
public void GiveAMessage(string message)
{
Debug.Log(message);
}
}
Can help me somebody, or say how that can work?
thanks in advance for help.
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.
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.
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.