- Home /
A general script variable
I want to create a general and public variable that will hold a script.
like: "var obj : GameObject;" will hold a GameObject. (it will probably be something like "var s : Script" but a bit diffrent)
Is anyone knows this syntax?
There's nothing wrong the your example of var obj:GameObject; are you getting an error?
Answer by Bunny83 · Aug 28, 2013 at 02:14 AM
If you need a variable that holds a reference to any kind of script you can use the base class, MonoBehaviour.
// UnityScript
var someVar : MonoBehaviour;
// C#
public MonoBehaviour someVar;
Keep in mind that you can't access script specific stuff in this case. "someVar" only has the base variables / functions.
Btw: It's way easier to answer the question or give an alternate solution if we know what you need this for. The less you write the more general the answers will be.
Answer by Eric5h5 · Aug 28, 2013 at 01:15 AM
var myScript : NameOfScript;
(By the way, don't just blindly type "NameOfScript"; you're supposed to actually use the name of the actual script.)
Answer by Jona-Marklund · Aug 28, 2013 at 01:10 AM
var s : "ScriptType";
An example follows
Enemy.js
var enemyScript : Enemy;
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Need a link to a Machine gun Script Please 1 Answer
Footsteps Java Script Problems 0 Answers
4.6 UI Pause Menu 1 Answer