x


How can I make robot fire a machine gun?

Using the robot from the FPSTutorial, is there a way I can make it fire a machine gun instead of fireing a rocket launcher? Also if I have a model with a @walk @idle @shoot @run models with it can I use the script for the robot on my model?

more ▼

asked May 31 '10 at 09:34 AM

Epic gravatar image

Epic
98 6 6 13

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

1 answer: sort newest

yes, and here's the code for shooting the machine

/*
create and attach a firepoint to this script, also create a bullet(Has to be a rigidbody) as a prefab and drag the prefab to the 'Projectile' variable.
bulletcount is how many bullets there is in one magazine before it reloads and power is the power you shoot the bullet
*/
var firepoint: Transform;
var projectile: Rigidbody;
var bulletcount: int = 80;
var power : int = 1000;
var ReloadDelayTime : float = 20;
////////////////////////////////////////////////////////////
private var currentreloaddelaytime : float;
private var overallbulletcount: int;
private var currentbulletcount: int;
private var reloading : boolean = false;
////////////////////////////////////////////////////////////
function Start()
{
    ////////////////////////////////////////////////////////////
    currentbulletcount = bulletcount;
}

// Instantiate a prefab with an attached Missile script
function Update () {
////////////////////////////////////////////////////////////
if (currentbulletcount >= 1 && delaying == false)
    {
        if(Input.GetButton("Fire2"))
            {
                var bullit = Instantiate(projectile, firepoint.transform.position, firepoint.transform.rotation);
                currentbulletcount -= 1;
                overallbulletcount += 1;
                bullit.rigidbody.AddForce(firepoint.transform.forward * power);
            }
    }
////////////////////////////////////////////////////////////
if (currentreloaddelaytime >= ReloadDelayTime)
    {
        currentreloaddelaytime = 0;
        currentbulletcount = bulletcount;
        reloading = false;
    }
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
if(currentshootdelaytime == shootDelayTime)
{
    delaying = false;
    currentshootdelaytime = 0;
}
}
////////////////////////////////////////////////////////////    
function OnGUI()
{
////////////////////////////////////////////////////////////
    if (reloading == false){
        GUI.Label(Rect(30,40,160,80), "Machinegun Ammo = " +currentbulletcount);
    }
    else{
        GUI.Label(Rect(30,40,160,80), "reloading");
    }
////////////////////////////////////////////////////////////
    GUI.Label(Rect(30,80,160,80), "You shot " + overallbulletcount + " bullets");
}
////////////////////////////////////////////////////////////
function LateUpdate(){
////////////////////////////////////////////////////////////
    if (currentbulletcount <= 0)
    {
        currentreloaddelaytime += Time.deltaTime;
        reloading = true;
    }
////////////////////////////////////////////////////////////    
}
more ▼

answered Jun 21 '10 at 01:16 AM

Ben 9 gravatar image

Ben 9
21 3

(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:

x446
x82
x29
x19

asked: May 31 '10 at 09:34 AM

Seen: 1219 times

Last Updated: May 31 '10 at 09:34 AM