Hi, I’m just starting with Unity and I’m struggling to access static variables like Vector3.up, Vector3.down dynamically. I want to check possible collisions via Raycast in a loop, so this is what I ended up with:
public var rays : Hashtable = new Hashtable();
function Update() {
var directions = ["forward", "left", "right", "up", "down"];
for(var dir : String in directions) {
var tmpRay : RaycastHit;
var tmpBool : boolean = Physics.Raycast( transform.position,
transform.TransformDirection(Vector3[dir]),
tmpRay,
1 );
rays[dir] = tmpRay;
rays['is'+dir] = tmpBool;
}
}
When I try to access the static variables of Vector3 (forward, left etc.) via iteration (I tried
Vector3[dir]
for this), I get:
BCE0048: Type 'System.Type' does not support slicing.
In Javascript this would work.
Is there any way to access static variables like this?
I’m beginning to wonder if there is any reason to use UnityScript if I can’t play with objects like I’m used to in Javascript. Thanks for any advice!
Edit: from what I can tell after a few hours with UnityScript: normal loose Javascript objects don’t work at all in Unity. I have to get my head around Unitys data structures. Correct me if I’m wrong