I’m a bit confused. Until I upgraded from beta5 to beta6, this worked fine:
private var tiltToTurn : TiltToTurn;
function Awake() {
tiltToTurn = gameObject.GetComponent (TiltToTurn);
}
(TiltToTurn is the name of one of my scripts).
Now I get a complier error:
Assets/Player/Jump2.js(55,48): BCE0022: Cannot convert ‘UnityEngine.Component’ to ‘TiltToTurn’.
Has the compiler’s behaviour become more strict? If so, can anyone tell what subtlety I have failed to grasp?
There are a few other examples of casting not working right after my upgrade. Here’s another:
var playerModel : GameObject;
var plumeMaterial : Material;
var plumePrefab : Transform;
var switchedOn = false;
var myRigidbody : Rigidbody;
var emitterForce: Vector3;
var plume : GameObject;
function Awake() {
myRigidbody = rigidbody;
}
function OnCollisionEnter(collision : Collision) {
if (collision.gameObject.layer == 9) {
if (switchedOn) {
var contact = collision.contacts[0];
var rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
var pos = contact.point;
plume = Instantiate(plumePrefab, pos,rot);
}
}
}
…the line plume = Instantiate(plumePrefab, pos,rot);
throws this:
Assets/Player/CrashEmitter.js(23,45): BCE0022: Cannot convert ‘UnityEngine.Object’ to ‘UnityEngine.GameObject’.
I had a bunch of problems when I tried to open a current Unity iPhone 1.7 project in Unity 3 a little while back.
Are these problems in conversion going to remain in the final release of Unity 3 (i.e. a lot of recoding to correct syntax problems when opening older projects) or is the issue simply that the project conversion isn’t fully fleshed out yet in the betas?
on the iphone its a known behavior, not a problem actually (no dynamic typing there at all)
On U3 it might not be a problem either but a consequence of the presence of generics on UnityScript since Beta 6 (as mentioned, see changelog)
And there is now officially no JS anymore, its called UnityScript from what I’ve seen (finally, cause JS caused a lot of missunderstanding and with generics now its not even in the same league anymore)