- Home /
How do I make a box in inspector appear that allows me to call functions in scripts similar to OnClick on Buttons?
Basically, I want to create a generic script that I can attach to objects that, when activated, calls a function within another script. I want to be able to pick which script is used and which function is called just like a button, but without the button (My plan is to raycast when the player hits the interact input, check if the object that was hit has this generic script, and if it does, activate it). Obviously though I don't want to create tons of copies of this script for each different object with unique functionality.
Here's a picture of what I'm talking about:
I just want to be able to use that with my script.
Answer by PizzaPie · Sep 12, 2018 at 07:49 PM
UnityEvent class is what you are looking for, something like this would do the trick:
public class MyClass : MonoBehaviour
{
public UnityEngine.Events.UnityEvent OnStartEvent;
private void Start()
{
OnStartEvent.Invoke();
}
}
Cheers
Answer by dan_wipf · Sep 13, 2018 at 08:29 AM
well i’d sugest you build your own editor.
but that will take some time! and could be frustrating!
—
are there many gameobjects, which you want to handle this way?
Your answer
Follow this Question
Related Questions
Inspector scripting, adding lists, checkboxes and buttons [With Image] 0 Answers
Custom Event: why is my method not listed in the inspector's dropdown? 1 Answer
GUI Editor Drag and Drop (Inspector) 1 Answer
Script to respond to event chosen from Inspector 0 Answers
Inspector button for custom class 1 Answer