- Home /
can't place inherited class of an abstract class in editor?
I saw this:
http://answers.unity3d.com/questions/24635/can-abstract-classes-inherit-abstract-methods-with.html
So I basically built two classes one my abstract class as such:
public abstract class TriggeredScript : MonoBehaviour
{
public abstract void RunTrigger();
public abstract void StopTrigger();
}
Then I created a more specific script:
public class GasScript : TriggeredScript
{
// Use this for initialization
public Rect area;
void Start ()
{
}
...
}
Then I have a game object with a script on it:
public class Switch : MonoBehaviour
{
public DoorTrigger[] doorTriggers;
public TriggeredScript[] eventTriggers;
public bool sticky;
...
}
in the editor it has TriggeredScript which my GasScript extends, why can it not add it in the editor to the field?
(yes its an array and i have the size as one showing one slot but cannot drag the script over)
is this kind of encapsulation just not handled by unity especially in the editor ?? or fingers crossed am I just doing something dumb and missing to add or do something else.
edit FIGURED IT OUT! I will answer my own question for posterity, but it seems I had to drop the GasScript on a Gameobject, and set the array that has triggered script to the gameobject with the script. Why this seemed different this time I don't know, in fact it is always like that?! Oh well, fixed!
if i can find the delete I might do that cause this was just me being dumb.
You should be able to drag a GameObject with the Component GasScript onto the array, not the script itself. Otherwise I'm not sure what's going wrong.
let me set up a screen shot...
so nope tried again no can do, no idea what I am missing...
Answer by rutter · Aug 15, 2014 at 04:39 AM
Judging by comments, you're trying to drag the script file itself into the inspector field.
So, your variable:
public TriggeredScript[] eventTriggers;
It's an array of references to objects of type TriggeredScript
.
And the value you're trying to drop in? That's a class. Classes aren't objects.
The class TriggeredScript
defines all the things that objects of that type can do... but the class itself is only a template for an object. It's sort of like the difference between a blueprint and a house.
If you have a GasScript
that exists in your scene, that's an object, which you should be able to drop into the inspector field.
Your answer
Follow this Question
Related Questions
Inheritance from object to object 1 Answer
How do I write this C# snipet in java script? 1 Answer
Problem using variable of type CustomStat to indicate which player statistic to change 1 Answer
FPS weapons class structure 1 Answer
Calling a method of a class that is a part of another class? 1 Answer