I’ve read some stuff off the forums about how Unity on the iPhone needs strict JS coding, but I’m having a hard time figuring out how to achieve this. My code in Unity works great, but when I bring it to the iPhone, I get around 20 errors (with different variables) along the lines of
Assets/scripts/collideTimer.js(7,40): BCE0019: 'collideTime' is not a member of 'UnityEngine.Component'
Here’s an example of one of the lines it’s pointing to:
#pragma strict
var target : Transform;
function Update () {
script = target.GetComponent( "carController" );
var collideTime : int = script.collideTime; // <--- This line is causing problems
gameObject.transform.guiText.text = "Collide Time: " + collideTime.ToString();
}
From my carController script, the line that calls the variable is this:
var collideTime : int = 0;
I have a bunch of errors that are exactly the same problem, it’s happening when I’m calling a script from another game object and trying to use a variable from it.
What can I do to avoid this error? Is there a good resource for strict JS for Unity iPhone?
You are right, sorry, my error.
Had the regular time values of Unity which are all non-int in my mind when answering not a specific one you created.
and yes you are right, its the casting because otherwise script is not a CarComponent and it fails because the field you try to use does not even exist.
Thanks Jessy! That worked great. I went through and got all my errors fixed.
Dreamora, you’re right. collideTime shouldn’t be an int, and I’m going to fix that as soon as I get a chance, as what I’m using it for is inconsistent between platforms. Right now it’s just an int that’s incremented on every Update() if the car is colliding with something - not a great way to get actual time.