- Home /
Instantiating objects as in javascript
In javascript I can very efficiently initialize an object at the same moment I declare it, as in:
var mylevel = {
levelName : "Hounds of Hades",
weapons : ["unseeing eye of al mualim", "laser sword"],
enemies: ["Dementos", "matter eater lad"]
}
Unity seems to hate this. What's the best way to manage this kind of constant data? Do I have to declare a class, instantiate it, and then use dot syntax or constructors?
Answer by Eric5h5 · Nov 10, 2012 at 10:01 PM
Yes, you declare a class and use constructors etc. It's best to think of Unityscript as being like ActionScript 3, not Javascript.
Your answer
![](https://koobas.hobune.stream/wayback/20220613083647im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
If the game has registered a PlayerPrefs then some code will happen 1 Answer
Saving object locations after game close 1 Answer
Copy values from one object (scriptwise) to another 1 Answer
How to conect rigidbodies, and then disconnect them when desired 3 Answers