Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Field for c# Script for the Inspector / Drag and drop external scripts

Discussion in 'Scripting' started by Rayman1337, May 28, 2018.

  1. Rayman1337

    Rayman1337

    Joined:
    Apr 26, 2013
    Posts:
    2
    I'm about to build a basic input/event -> output system.
    This system should accept scripts from other users that derivative from an "Action" class and override the method "perform()". Those scripts just get added via the inspector.

    Here is the problem. The inspector only allows "Object" class scripts to be dragged in, what kills the derivation and can't access the "perform()" method.

    If i define the field to be an "Action" class object it does not allow any object to be dragged in.
    If i make the script and field a standard Monbehavior it also does not allow the script to be dragged in.

    Thanks in advance.
     
  2. Pavlon

    Pavlon

    Joined:
    Apr 15, 2015
    Posts:
    191
    Code (CSharp):
    1.     public MonoBehaviour behaviour; // drag any script that inherits a MonoBehaviour in the editor
    2.  
    3.     public void Perform()
    4.     {
    5.         behaviour.enabled = true;//Start your script
    6.     }