I am trying to use ‘ScriptableObject’ object to instance from a JS script. Is this not possible? The docs are pretty thin on ‘ScriptableObject’ and there is not much in the forums.
tanks (boom)
–Roy
I am trying to use ‘ScriptableObject’ object to instance from a JS script. Is this not possible? The docs are pretty thin on ‘ScriptableObject’ and there is not much in the forums.
tanks (boom)
–Roy
You can use JS. I have attached a simple test that contains two JS scripts. On script is a JS class that extends/inherits from ScriptableObject
class SOScript extends ScriptableObject
{
function SayHello() {
Debug.Log("Hello");
}
}
The scecond script is attached to the main camera and basically instantiates an instance of the SOScript class and calls the SayHello() method.
function Update () {
if (Input.GetKeyDown("n")) {
var w : SOScript = ScriptableObject.CreateInstance("SOScript");
w.SayHello();
}
}
It looks like the JS Compiler is not flexible enough to allow the runtime typing in this situation.
many thanks! I was missing the part:
class SOScript extends ScriptableObject
so it was throwing an error.
I’m coming to Unity from Director and maybe doing some contortions to use the methodologies I developed in Director rather than using a more Unity-based approach (for example the whole ‘prefab’ schema).
I’m still sorting out which is the more flexible for creating content on the fly - and particulary which is the more usable from project to project. The Unity GUI is nice but sometimes I just want to call a script to set up a level and not tinker with entering params in the UI. Still trying to get my mind around all this. Thanks for the help!
–Roy
I come from coding background so I feel the same way about using code to set up levels. So I write my code then call it either in game from the Editor so I can quickly check stuff and change the code and then remake the level without starting the game. My scripts generally instatiate and place prefabs then tweak them if needed.
http://unity3d.com/Documentation/ScriptReference/Object.Instantiate.html
I use
@MenuItem ("GameObject/Board-Setup1")
static function Setup3 () {
Selection.activeTransform.SendMessage("Setup1");
}
it has to be placed in the standard assets/editor folder I think. I select the level or element of the level I want to setup and the in the IDE meniu choose GameObject/Board-Setup1.
http://unity3d.com/Documentation/ScriptReference/MenuItem.html
right now I writing something to examine levels I build by hand in the IDE and save them into data structures so I can create them with tweak them in code.
Cheers,
Grant
Hi grant,
thanks for the perspective. I’d be interested to hear how it goes with saving IDE set ups to code/data - that could be a great workflow solution for the problem of having multiple people working on the same project (as in my case - there are 3 people working on content/code that needs to exist in a level - and also be reused as boilerplate in other levels).
-roy
I am not doing a FPS but a board based game so I can layout the board by code in a regular pattern but each level has different configurations that are arbitrary changes. So Iselect the tile that I have changed and run my script(via the menu). This copies (using Instantiate) the tile over to a an empty game object (Level) that I have setup to hold changes. It also sets some information in public variables of attached scripts. I can run another menu choice which then iterates over Level and applies the changes to the standard board. Since I am still changing my tiles prefab alot it lets me restoreindiviual customiztions even when the underlying tile prefab has changed.
I am working alone so my work flow does not handle multiple people changing things and conflick avaoidance. You could have the script serialize the public variable to another script in your script folder.
I have my whole project in an Eclipse folder. This lets me edit with Eclipse and I have the scripts folder under SVN(subversion) so I can recover from my really bad coding errors. Also eclipse keeps a local nonSVN diff of every save it makes. Instead of Eclipse you could just put the scripts folder under SVN using a SVN command line or Mac GUI. I haven’t tried this but It should work. you just have to run the commits from out side Unity every hour or what ever by hand.
If you do put the Unity project under SVN remember to svn ignore the temp folder (I forgot and now things are a bit screwed up).
I use a SVN service on the web(wush.net), at $20/month it is hard to justify even a couple hours time to setup one myself. I have not tried to restore anything except scripts yet (and that was only to test that it works) so don’t know about how it will work with othe assets. If you have to I would suggest doing an export to another folder of the whole project then using Unity to export/Import assets.
Cheers,
Grant