Hi all!
I’m having a hard time finding documentation of Unity classes (particularly in Javascript, which is the language I am working in).
In other programming languages I have worked in I have always instantiated a class and it would then be that classes responsibility to deal with assets. Unity gives me the impression that it should be backwards: you instantiate the asset and then attach a class to it. Is this correct? it sounds pretty inelegant.
I’m finding myself designing classes like this:
public class Block{
var velocity = new Vector3(0,0,0);
var position = new Vector3(0,0,0);
// etc
var model: GameObject;
// Constructor
function Block(x: int, y: int, z: int){
// Build the model instance
}
// Deconstructor
function Destroy(){
// Delete the model instance
}
function Tick(){
// Move, set the position of the model, etc
}
}
As the game gets more complicated, I’m finding this approach is giving me a lot of problems. I’m having a lot of issues with scope, and what I assume is a problem with referencing/dereferencing.
I suppose what I’m asking is this: is there a good Javascript example out there that makes significant use of classes?
Thanks!