Hi, Im now working on giving my gun limited ammo, but is not working correctly:
var fire : AudioClip;
var reload : AudioClip;
var shooting : boolean = false;
var reloading : boolean = false;
var crosshairTexture : Texture2D;
var ammoCount : int = 17;
var position : Rect;
private var clipCount : int = 1;
function Start()
{
position = Rect( ( Screen.width - crosshairTexture.width ) / 2, ( Screen.height -
crosshairTexture.height ) / 2, crosshairTexture.width, crosshairTexture.height );
}
function OnGUI()
{
GUI.DrawTexture( position, crosshairTexture );
}
function Update ()
{
if(Input.GetButtonDown("Reload") !reloading || ammoCount < 1 clipCount > 1) {
Reload();
clipCount =- 1;
}
if (Input.GetKey("w"))
Walk();
if (Input.GetKey("s"))
Walk();
if (Input.GetKey("a"))
Walk();
if (Input.GetKey("d"))
Walk();
else;
if(Input.GetButtonDown("Fire2")) {
animation.Play("Melee");
}
if(Input.GetButtonDown("Jump")) {
animation.Play("Jump");
}
if(Input.GetButtonDown("Flashlight")) {
animation.Play("Flashlight");
}
if (Input.GetButtonDown("Fire1") !shooting ammoCount > 1) {
Fire();
ammoCount =- 1;
}
}
function Fire() {
animation.Play ("Fire");
audio.PlayOneShot (fire);
shooting = true;
if(!animation.IsPlaying ("Fire")) {
shooting = false;
}
}
function Reload() {
animation.Play("Reload");
audio.PlayOneShot(reload);
reloading = true;
if(!animation.IsPlaying ("Reload")) {
reloading = false;
}
}
function Walk()
{
animation.Play("Walk");
}
Problems:
- Some how it sees that after I reload, the clipCount is less than 1, and wont do it again…
- also, it never stops firing to relaod or just quit…
- The fire sound is played every frame in the fire animation, not once, witch the var shooting is supposed to fix, it used to, but not any more…
Any tips? Corrections? Info on int variables? THX!!
:?