Like in flash, if I create a MovieClip, I can simply assign whatever variable within the MovieClip itself, like MovieClip.variable=something;
Is there a inherit way to do this for GameObjects? if not what are the normal approaches? Thanks
Like in flash, if I create a MovieClip, I can simply assign whatever variable within the MovieClip itself, like MovieClip.variable=something;
Is there a inherit way to do this for GameObjects? if not what are the normal approaches? Thanks
You can assign variables to game objects, components, etc, but you have to type it,
var anObject:GameObject = whatever;
Not a lot different than Flash. You are just using objects and static classes from the engine for your purpose. Best to read some of the docs, like the manual on scripting and the script reference for the classes.
but didn’t that like just create a separated game object variable on it’s own? I’m trying to declare a variable “nested” in the gameobject, “outside” of the gameobject where the game object were created dynamically.
GameObject.Find(“it”+i).pt=Vector2(0,i);
var GameObject.Find(“it”+i).pt=Vector2(0,i);
var _it=GetComponent(“it”+i);
var _it=GameObject.GetComponent(“it”+i);
_it.pt=Vector2(0,i);
none of these works.
EDIT: I don’t do JS so not going to comment on your example code
EDIT: Last link I provided is probably the one you want to look at
EDIT: Or not. Unity actually uses a spinoff off javascript called UnityScript so it could be that this documentation says things that are not entirely true for UnityScript. Although good portion of community will disagree with me my personal suggestion is to leave JS alone and use C# instead.
I’ve been working with Javascript in flash for few years now, those method that were shown on your web does not work in unity as unity script is not 100% native javascript, so I’m afraid that the link that you provide would not work, but thanks anyways. ^^
so pirs, how do you" define"(not access) a new variable in other game object’s script in c#? I’ll see if I can relate it to js.
I guess that sounds like Instantiate(), but that’s for prefabs. It’s hard for me to tell what you are asking for. What’s different about Unity is that it’s a component engine, so you can’t extend the classes and make new classes like you did in Flash(the newer Flash). You can only extend your own classes. What you were doing in Flash was mostly extending classes and using them for your own purpose. I like that kind of engine, but Unity isn’t that. Most of the time you start with an object, even if it’s an empty object, and you add components to it. Maybe they are script components, maybe physics, whatever. Most of the functions you are calling are for static classes and they can’t be extended. They are helper classes. It’s basically a different way of doing it, and you have to get used to it. Unity mainly uses prefabricated objects and components that are added. The scripts are behaviors that use those things.
Yup, I was talking about Initiate, if there isn’t a unity way to do it, then I guess I’ll just define an empty variable inside the prefab itself and alter it later then. That will work too. Thanks. ^^