- Home /
Does UnityScript (Javascript) support classes/structs?
I have not found an adequate answer to this question.
I need to keep track of positions of game objects I spawn via scripts. To do so, I would like to encapsulate the relevant data in a struct or class. I am wondering what it takes to do the equivalent in Javascript/UnityScript.
struct NPC
{
float x;
float y;
float z;
int age;
float money;
};
Does Javascript have an equivalent? I need to make arrays of these objects and rather than make 5 separate arrays of each type, I want to declare one array of just the object.
Thank you.
Answer by Fattie · Oct 06, 2012 at 08:42 AM
Sure, a struct in Unityscript is the keyword:
extends System.ValueType
Here's a critical distinction between structs and classes:
http://answers.unity3d.com/questions/261419/you-own-structs-passed-by-reference.html
there are many questions "how to Struct in unityscript" on this on the site, eg ...
http://answers.unity3d.com/questions/23044/struct-in-javascript.html
Your answer
Follow this Question
Related Questions
Where to use Structs and classes? 5 Answers
can't place inherited class of an abstract class in editor? 1 Answer
UnityScript struct causes unity to crash 1 Answer
Saving data to xml file (I have the loading down) 0 Answers
How do I access a script variable from a class defined within that script? 1 Answer