x


Shoot. Just Shoot

This is a very simple question but... can you give me a script so when i hit a key it shoots a certan game object.

Thanks!!!

(LEAVE INSTRUCTIONS!)

more ▼

asked May 07 '10 at 06:19 PM

Colin Allen gravatar image

Colin Allen
96 7 7 8

Please mark Eric's answer right as it is perfectly correct and likely the only answer you will get. Also, don't ask for scripts. Ask for help with scripts you are making.

May 08 '10 at 05:28 AM KHopcraft

@killer1390, don't expect a reply/checkmark. Some posters are like pandas - "eats, shoots, leaves"...

May 08 '10 at 02:23 PM Cyclops
(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

Have a look at the first-person shooter tutorial.

more ▼

answered May 07 '10 at 07:02 PM

Eric5h5 gravatar image

Eric5h5
81.5k 42 133 529

(comments are locked)
10|3000 characters needed characters left
public var snowballPrefab : Transform;
public var snowballSpeed : float = 6000;

function Update(){
    if(Input.GetButton("Fire1"))
        {
            if(!snowballPrefab || !snowballSpeed)
            {
                Debug.Log("[Shoot] 'bulletPrefab' or 'bulletSpeed' is undefined");
            }else{
                var snowballCreate = Instantiate(snowballPrefab, GameObject.Find("SSpawnPoint").transform.position, Quaternion.identity);
                snowballCreate.rigidbody.AddForce(transform.forward * snowballSpeed);
            }
        }
}

Try this, replace snowball with your game object. I am still trying to find out a better way:)

more ▼

answered Nov 17 '10 at 02:48 PM

LFZ2 gravatar image

LFZ2
128 5 5 14

what button is used to shoot???

Jul 09 '11 at 10:37 AM buskins

Fire 1 is the left mouse button :( See the keys in the Edit> Player Settings> Input

Jul 09 '11 at 11:02 AM Unamine
(comments are locked)
10|3000 characters needed characters left

put A empty game object in front of your gun ( where u want to shoot from) and name it "spawnPoint" then attach this script:

var fireRate : float = 0.1;
var Prefab: Transform;
private var nextFire = 0.0;
var speed : float = 50;
function Update () {
    if(Input.GetKey("mouse 0")&&Time.time > nextFire){
    nextFire = Time.time + fireRate;
    var copy = Instantiate(Prefab,GameObject.Find("spawnPoint").transform.position,transform.rotation);
    copy.rigidbody.velocity = transform.TransformDirection(Vector3.forward * speed);

}

}

to the player, you can edit the fire rate, in the inspecter panel make sure to when it says prefab, add a game object there, such as a cube or sphere.

more ▼

answered Jun 25 '12 at 04:08 AM

Bruno Fludzinski gravatar image

Bruno Fludzinski
104 9 22 28

(comments are locked)
10|3000 characters needed characters left

dont ask for scripts use the references and learn it yourself

more ▼

answered Jun 02 '12 at 08:23 AM

lblaz7 gravatar image

lblaz7
0 2 2 2

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x787
x672
x330
x286
x134

asked: May 07 '10 at 06:19 PM

Seen: 1616 times

Last Updated: Jun 25 '12 at 04:08 AM