Was able to do this in UnityScript before 3.4 update.
static var X = -0.20;
var ThisObject : GameObject = gameObject.Find("AGameObject");
ThisObject.transform.localPosition.x = X;
Can someone (re)write this code to work with #pragma strict?
Was able to do this in UnityScript before 3.4 update.
static var X = -0.20;
var ThisObject : GameObject = gameObject.Find("AGameObject");
ThisObject.transform.localPosition.x = X;
Can someone (re)write this code to work with #pragma strict?
removed as its none sense ![]()
No, GameObject.Find returns GameObject (would be pretty silly otherwise).
It doesn’t need to be rewritten, it works as-is (assuming you put the last two lines inside a function).
–Eric
indeed, didn’t think about the static initializer limitations that backfire more regularly on JS than C# where the compiler catches “impossibility”
Thanks @Dreamora and Eric5h5
Dreamora had me doubting myself… lol, I had never used the AS clause in js
and I was baffled to hear it did not return ‘GameObject’
That caused me gray matter to go !@#*^~%! but I stood fast and started to review my code…
Here is what I did to fix it:
OLD CODE FOR COMPARISON:
static var X = -0.20;
var ThisObject : GameObject = gameObject.Find("AGameObject");
ThisObject.transform.localPosition.x = X;
…as you can see the old code was updating each of 2 vector elements separately.
and yes, Eric, lines are in a function indeed(my bad for omitting to show that line) <-shown in new code
function SetCoords(X, Y, Z, Rot) {
The new code uses the Vector3 constructor…
but the error remained until I explicitly ‘typed’ the args.
Thus,
static var Y : float = -0.20;
function SetCoords(X : float, Y : float, Z : float, Rot : Quaternion) { <-culprit line, X,Y,Z were default type 'Object' even though float was passed
var ThisObject : GameObject = GameObject.Find("AGameObject");
ThisObject.transform.localPosition = Vector3(ThisObject.transform.localPosition.x, Y, Z);
...
}
I have not tested it yet, and I am wondering if the Vector3 call will also need explicit ‘typing’
I just wanted to be able to compile to continue my current work elsewhere in the app.
…just a matter of me brain being stuck in the auto-typing world of real js…
This new compiler will undoubtedly challenge me again.
static var X:float = -0.20;
var ThisObject:GameObject = GameObject.Find(“AGameObject”);
ThisObject.transform.localPosition.x = X;
Just a couple of formatting errors and a totally butchered static var X was the only problem I could see.
@hippocoder… sorry, the colon( : ) was not in my original code in the static… line.
I have now removed it in both my postings to avoid confusion.