- Home /
Class Reference in Editor not working
Hey,
I didn't really knew how to call the question or whatever this is. I have a script called "DebugSpawner" - some script to spawn some items in the environment and two additional script called "SpawnerScript" and "DebuggingSpawner".
You may know what I want to do but let me tell you :D
The spawner has some properties to be filled. Things like
public GameObject SpawnItem;
public SpawnerScript SpawnScript;
public float SpawnTime = 1500;
public float TimeRandom = 5;
public float Radius = 10;
public float PlayerRadius = 150;
Basically there is no problem without the
public SpawnerScript SpawnScript;
this really doesn't want to work like I want it to work.
If I'm assigning a script through the editor which inherits from SpawnerScript
the property keeps the value of "None (SpawnerScript)".
My SpawnerScript is like
public abstract class SpawnerScript : MonoBehaviour {
}
The DebuggingSpawner looks like
public class DebuggingSpawner : SpawnerScript {
void Update () {
Vector2 randPos = Random.insideUnitCircle;
gameObject.transform.position += new Vector3 ( randPos.x * 5, 0, randPos.y * 5 );
}
}
Some images to show you what I'm talking about. There you see that I'm able to select the right script but this is what is happening:
It keeps the value of "None":
Any help for this or how I can fix it?
Answer by flaviusxvii · Feb 10, 2013 at 04:32 PM
Your DebuggingSpawner script has to be attached to a GameObject. You can create an empty game object, attach your script to it, then it'll be accepted in that "SpawnerScript" field. Make it a prefab if you want to use it scene to scene.
a bit confusing that I can't add a blank script to another script but it's working now. Thanks.
You have to understand the difference between a Script which is a class and an instance of that class. A class is just the "blueprint" of that object. It's like you try to drive with the blueprints of a B$$anonymous$$W. You have to build one before you can use it.
A lot people seems to miss this little but important thing about OOP.
okay, OOP is not that problem but I'm new to Unity and have to learn these things from scratch.. It's a huge difference between the "normal" C# and this Unity thing.
I just pictured The Stig sitting on 1:1 scale B$$anonymous$$W blueprints making "vroom vroom" sounds and leaning into imagine corners.
It's a great analogy though. In OO, a class is just a schematic, and objects are the realization of that. Unity takes it a bit further with the $$anonymous$$onoBehavior class. A script that derives from $$anonymous$$onoBehaviour implicitly fits into a bigger picture of a GameObject.
Your answer
Follow this Question
Related Questions
Script variable 1 Answer
Declaring animations on a script in the editor 1 Answer
Variables not visible in editor but accessible from other scripts 2 Answers
customization of variables in script for in Editor? 2 Answers
Fastest way to instantiate and move multiple game objects in the editor 3 Answers