Hi, I have this script that I have been working on, and the problem is that I can’t get it to either put 30 rounds in the clip and subtract 30 from the cache, and to simply just put 30 in the clip or less based on if theres less in the cache. Im kindof confused now, and if anyone can point me to what I can do to do this, please help.
var isInteracting : boolean = false;
var ammoCache : int = 60;
var ammoClip : int = 30;
var fireRate : float = .2;
var timeToReload : float = 3;
var fireSound : AudioClip;
var reloadSound : AudioClip;
private var ammoHold : int;
private var cache : int;
private var clip : int;
function Update () {
cache = ammoCache;
clip = ammoClip;
cache += clip = ammoHold;
if (Input.GetButtonDown("Reload") isInteracting == false ammoClip <= 30 ammoCache >= 0 || ammoClip <= 0 ammoCache >= 1) {
Reload();
}
if (Input.GetButton("Fire1") isInteracting == false ammoClip >= 0) {
Fire();
} else if (!animation.isPlaying) {
animation.Play ("Neutral");
}
if (ammoClip <= 1) {
isInteracting = true;
}
}
function Fire() {
isInteracting = true;
audio.PlayOneShot (fireSound);
animation.Play ("Fire");
ammoClip --;
Debug.Log (ammoClip);
yield WaitForSeconds (fireRate);
isInteracting = false;
}
function Reload() {
if (ammoCache <= 29 ammoHold <= 30) {
isInteracting = true;
ammoClip = ammoCache;
audio.PlayOneShot (reloadSound);
animation.Play ("Reload");
ammoCache = 0;
yield WaitForSeconds (timeToReload);
isInteracting = false;
Debug.Log (ammoCache);
} else if (ammoCache <29 ammoHold >= 30 || ammoCache <= 30 ammoHold >= 30) {
isInteracting = true;
audio.PlayOneShot (reloadSound);
animation.Play ("Reload");
ammoClip = 30;
ammoCache -= ammoHold;
yield WaitForSeconds (timeToReload);
isInteracting = false;
Debug.Log (ammoCache);
}
}
//static function ClipPlus() {
//ammoCache += 30;
//}
@script RequireComponent (AudioSource)
Also, heres the gun model. Thanks.
277420–9950–$ak_47_modeljas_141.zip (28.1 KB)