So, Im pretty new to unity, and c#, and Im trying to make a system where I can attach a script to an object in unity, and then assign a certain script to this object, so when the player interacts with it, it will call a script. so...
here is where i need to be able to put a script:
and
here is what I have currently:
Not exactly what you want(I think what you want is bad practise or unachievable), but you can obtain same functionality via following steps,
First you need to create prefab which your script attached to it. Here is small tutorial for that. Then you can use following code.
public GameObject myPrefab;
// This script will simply instantiate the Prefab when the game starts.
void Update()
{
if(Input.GetKeyDown("f")){
// Instantiate at position (0, 0, 0) and zero rotation.
Instantiate(myPrefab, new Vector3(0, 0, 0), Quaternion.identity);
}
}
Create an Action Class or an interface deriving from Monobehaviour.
public abstract class Action : Monobehaviour {
public virtual void executeAction();
...
And then create actual actions deriving from that abstract base:
public class DestructionAction : Action {
public override void executeAction()
{
// the actual action code
}
...
That way, you can create a lot of different actions. Your "Interaction Code" Script needs a Slot of type "Action" (the abstract base class).
Learn more about Overriding here: https://learn.unity.com/tutorial/overriding#5c893d46edbc2a0d28f48954