I have a class that stores a reference to a current gameObject as well as some custom properties. I have placed it is a separate .js file. Now I would like to create instances of that class as I instantiate game objects (I have simplified the script to exclude the instantiation code).
EDIT: OK, it looks like using a ScriptableObject is a better way to go. I have adjusted the scripts.
//Gob.js
Class Gob extends ScriptableObject {
var _name :String; // the name of the gameObject inside unity (also, the key to the dictionary)
var _prefab :Transform =null; // the prefab this obj was cloned from
var _transform :Transform; // the actual gameObject.transform inside unity
var _cell :Vector3; // using vector 3, but really just a triplet (x, y, z) of ints so I can get to world(x, y, z)
var _type :String;
var _isVisible :boolean;
}
And I am trying to make use of it inside another file:
//MakeWorld.js
private var _gobs :Dictionary.<String, Gob>;
function Start() {
AddToWorld();
}
function AddToWorld() {
var x=10;
var y=5;
var z=13;
var name ="A0:" +x.ToString() +"-" +y.ToString() +"-" +z.ToString();
var gob :ScriptableObject = ScriptableObject.CreateInstance("Gob");
gob._cell =Vector3(x, y, z);
gob._type ="A0";
gob._orig_type =gob._type;
gob._isVisible =true;
gob._name =name;
_gobs.Add(gob._name, gob);
}
The error now is that ‘_cell’ is not a member of ‘UnityEngine.ScriptableObject’. Any help/suggestions will be appreciated.