I am following the fps trailer (http://download.unity3d.com/support/resources/files/FPS_Tutorial_1.pdf) and written in the missile launcher code and attached the sphere prefab to in to the hierarchy like it says but the launcher still wont fire!
Here is the code :
var projectile :
var speed = 20;
if( Input.GetButtonDown( "Fire1" ) )
var instantiatedProjectile : Rigidbody = Instantiate(
projectile, transform.position, transform.rotation );
transform.TransformDirection( Vector3( 0, 0, speed ) );
Physics.IgnoreCollision( instantiatedProjectile. collider,
Any help would be great.
EDITED by @whydoidoit - code formatted.
This code seems ok - maybe it’s not attached to the rocket launcher, or the prefab isn’t correctly defined. Follow these steps:
1- Drag the script from the Project view to the rocket launcher in the Hierarchy view;
2- Select the rocket launcher in the Hierarchy view, then drag the prefab from the Project view to the field Projectile in the Inspector - this will save a reference to the prefab in the variable projectile in the script that’s attached to the rocket launcher.
1- This code will launch the projectile in the rocket launcher’s forward direction (the blue axis). If the projectile always goes in the same wrong direction, your rocket launcher probably isn’t correctly rotated.
2- Pay attention to the console messages, specially to Null Reference errors - they usually say that you’ve forgot to define a prefab, assign a variable etc.