shooting somthig

Hi, can you please tell me the steps of shooting a gun in Unity 3D? I really need HELP!!!!

3 Answers

3

http://www.youtube.com/watch?v=wfpZ7_aFoko

var projectile : Rigidbody; private var speed = 5;

 function Update()
        {
  if(Input.GetButtonDown("Fire1")) {    
  var instantiatedProjectile : Rigidbody = Instantiate(projectile, transform.position,         transform.rotation);

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

Give your object that you are firing a rigidbody (then turn off gravity)

–

This is very simple to do. Try this and it will shoot what you want to shoot.

//place your name of shooting target here. In inspector the projectile has to have a rigidbody
var gameObject = Rigidbody;

function Update ()
{
     //When you the left mouse button fires the gameObject
     if ( Input.GetButtonDown (Fire1) )
     {
         //the shooting part of the function. Create empty gameObject place under your player and name spawnPoint. Then place this script on top of main player gameObject
         var gameObject : Instantiate(gameObject, transform.Find(spawnPoints).transform.position, Quaternion.identity);

         //adding force to projectile
         Rigidbody.AddForce : gameObject(forward * 500);
     }
}

This script is very easy to make and use.