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;
}
////////////////////////////////////////////////////////////
}
answered
Jun 21 '10 at 01:16 AM
Ben 9
21
●
3