- Home /
How to perform Explicit typecasting in UnityScript?
Typecasting as in from Object to GameObject, int to float etc.
Answer by Eric5h5 · Jul 05, 2012 at 05:37 PM
You can use "as" for reference types.
var foo : Object;
var bar = foo as GameObject;
There isn't a direct method for value types, but you can use parseFloat or parseInt in the case of floats and ints.
To be fair, he said "UnityScript" not Javascript, nor C#, nor Boo. So it wasn't very specific.
I guess we all call Javascript Unity Script here to be clear that it isn't actually Javascript. Unity internally compiles to a UnityScript dll when you write 'Javascript'
Yes - and given that it makes everyone think it is real Javascript that is a very big shame (given the massive differences). Hence many people specifically call it Unity Script to try to be clear or to raise the question and make the point.
I agree that this is not an ideal situation.
Yep. I guess the point I was trying to make was that I didn't know UnityScript meant JavaScript. I'll keep that in $$anonymous$$d next time.
I am sorry if i haven't made myself clear to others.
The JavaScript Unity uses is in many ways different from normal JavaScript ( the original language ). So i asked about UnityScript, i.e. Unity's JavaScript. @ThePunisher
Answer by nventimiglia · Jul 05, 2012 at 05:36 PM
float myHealth = 10f;
int healthA = myHealth as int;
int healthB = (int)myHealth;
Bizarrely, the question specifically asks for UnityScript and people post C# answers...not helpful....
Your answer
![](https://koobas.hobune.stream/wayback/20220613073742im_/https://answers.unity.com/themes/thub/images/avi.jpg)