Build and run question, iOS, newbie question

I've made a little game - a very typical spaceship shooter (like space invaders - to try something completely new :))

Anyway - the game works just fine when I test it in unity and I get no compiling errors in the console, but when I chose to build and run to test the game on the iPhone i get these two messagea in the console:


Assests/flyBulletFly.js(10,32): BCE0019: 'rigidbody' is not a member of 'UnityEngine.Object".

Error building Player because scripts had compiler errors UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()


the script the message refers to looks like this:

var bulletSpeed : float; var prefabBullet : Transform;

function Update () {

if(Input.GetButtonUp("Jump")){

    var instanceBullet = Instantiate(prefabBullet, transform.position, Quaternion.identity);
    instanceBullet.rigidbody.AddForce(transform.forward * bulletSpeed); 

}

}

Can someone help me please!

Thanks Jeppe (upcoming developer taking baby steps)

Put "#pragma strict" at the top of all scripts when using JS with an iOS (or Android) target, and fix all resulting dynamic typing errors. For example, Instantiate returns Object, which is making instanceBullet be type Object, which works OK with dynamic typing (except slower), but won't work without dynamic typing. So you need to cast that to a GameObject in this case.

Put "#pragma strict" at the top of all scripts when using JS with an iOS (or Android) target

Thank you for this! ... when I add the "#pragma strict" the compiler will no longer accept my script, again referring to: 'rigidbody' is not a member of 'UnityEngine.Object".

What am I overlooking - rigidbody should indeed be part of the unityEngine?

the script looks like this:


var bulletSpeed : float; var prefabBullet : Transform;

function Update () {

if(Input.GetButtonUp("Jump")){

var instanceBullet = Instantiate(prefabBullet, transform.position, Quaternion.identity);
instanceBullet.rigidbody.AddForce(transform.forward * bulletSpeed); 

}

}


Can you help me?

Thanks Jeppe

You have to type the Transform as a GameObject AND type the Instantiate function as a GameObject as well. I didnt need to add "#pragma strict" to make it work

var bullet:GameObject; var shootForce:float = 10;

function Update() {

if(Input.GetMouseButtonDown(0))
{
    var instanceBullet  = Instantiate(bullet,transform.position,Quaternion.identity) as GameObject;
    instanceBullet.rigidbody.AddForce(transform.forward *shootForce);
}   

}