- Home /
Basic scripting help (FPS Tutorial)
I'm new to Unity3D, and i have no experience with scripting whatsoever. I followed the instructions on Unity's FPS tutorial, but now I'm stuck with the MissileLauncher.js thing. I get two errors. Both of them say 'BCE0005: Unknown identifier', one for projectile, the other for speed. I seem to get problems on variable declaring. Please help.
function Start ()
{
var projectile : Rigidbody;
var speed = 20;
}
function Update()
{
if( Input.GetButtonDown( "Fire1" ) )
{
var instantiatedProjectile : Rigidbody = Instantiate( projectile, transform.position, transform.rotation );
instantiatedProjectile.velocity = transform.TransformDirection( Vector3( 0, 0, speed ) );
Physics.IgnoreCollision( instantiatedProjectile. collider, transform.root.collider );
}
}
for very basic program$$anonymous$$g help, try reading all of unityGE$$anonymous$$S.com
Answer by bompi88 · Dec 14, 2012 at 07:29 PM
Since you are using those variables in the update function, it's necessary to declare them either inside of the update function (not recommended because this will happen every frame.) or as global variables. You declare global variables in the top of the script and outside of any function/method, like this:
var projectile : Rigidbody;
var speed : float = 20;
function Update()
{
if( Input.GetButtonDown( "Fire1" ) )
{
var instantiatedProjectile : Rigidbody = Instantiate( projectile, transform.position, transform.rotation );
instantiatedProjectile.velocity = transform.TransformDirection( Vector3( 0, 0, speed ) );
Physics.IgnoreCollision( instantiatedProjectile. collider, transform.root.collider );
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613085424im_/https://answers.unity.com/themes/thub/images/avi.jpg)