x


ammo count

can anyone build off my script of give me an idea or tutorial on how to count ammo. Here is my script. (it a js.)


var bullet : Rigidbody;
var speed = 50;

function Update () 
{
    if(Input.GetButtonDown("Fire2"))
    {
        var clonedBullet : Rigidbody = Instantiate(bullet, transform.position, transform.rotation);
        clonedBullet.velocity = transform.TransformDirection(Vector3(0,0,speed));
    }
}
more ▼

asked Jun 25 '12 at 07:07 PM

tss gravatar image

tss
25 2 7 12

I love to answer, but I don't have the time right now. If you haven't got the answer you need tomorrow, I will post one.

Jun 25 '12 at 07:11 PM Hybris

seems someone answered! Please mark it as good, so I can know if I have to post or not

Jun 25 '12 at 07:17 PM Hybris

it is answered

Jun 26 '12 at 04:31 PM tss
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
var bullet: Rigidbody;
var speed = 50;
var AMMO = 10;

function Update()
{
    if(Input.GetButtonDown("Fire2"))
    {
        if(AMMO > 0)
        {
            var clonedBullet : Rigidbody = Instantiate(bullet,transform.position,transform.rotation);
            clonedBullet.velocity = transform.TransformDirection(Vector3(0,0,speed));
            AMMO --;
        } // You forgot that one
        else{
            print("NOAMMO");
        }
    } // And those two
}

this Checks if it has ammo otherwise it wont shoot at all.

more ▼

answered Jun 25 '12 at 07:12 PM

chiggafoo gravatar image

chiggafoo
59 9 13 14

if(AMMO>=0){

Thats what it says but that means it can shoot if the ammo = 0.

Jun 25 '12 at 07:18 PM Hybris

Hybris is right.

Be careful with the codes you give, you forgot severals brackets. And both OP and chiggafoo, please format your codes properly next time.

Jun 25 '12 at 07:27 PM Berenger

Yeah sorry! And it should be > instead of >= ill fix that

Jun 25 '12 at 09:55 PM chiggafoo

thank you

Jun 25 '12 at 11:46 PM tss
(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:

x3463
x446
x66

asked: Jun 25 '12 at 07:07 PM

Seen: 516 times

Last Updated: Jun 26 '12 at 04:31 PM