Wednesday, June 29, 2011

Unity FPS Shooter Game Tutorial #3

Here is a modification in the launcher script to shoot two types of weapons
=================================================================================================================================================================================================================================

var projectile : Rigidbody;
var projectile2 : 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 );



}



if( Input.GetButtonDown( "Fire2" ) )
{

         var instantiatedProjectile2 : Rigidbody = Instantiate(
projectile2, transform.position, transform.rotation );


instantiatedProjectile2.velocity =
transform.TransformDirection( Vector3( 0, 0, speed ) );


   Physics.IgnoreCollision( instantiatedProjectile. collider,
     transform.root.collider );



}








}
==============================================================================================================================================================================================================================















Here is the two rigid bodies are a sphere (red sphere) and a cube(Xcube)

No comments:

Post a Comment