- Home /
reload gun
hi, I have script c# about reload 30/270 and the other one it javascript about shoot, I put in script c#: when player press r gun reload and disable java script for Ending bullets, but the bullets ends when i reload , I want to make the bullets ends when the number of bullets be 0/0
this is my script:
using UnityEngine;
using System.Collections;
public class chargeweapon : MonoBehaviour {
public float MaxAmmoAmount;
public float CurAmmoAmount;
public Texture2D AmmoGUI;
public float ReloadSpeed;
public AudioClip Shotsound;
public GameObject MagazineGB;
public AudioClip Chargersound;
float reloadSpeedModifier;
bool canReload;
bool didplayerreloadinganim;
// Use this for initialization
void Start () {
reloadSpeedModifier = ReloadSpeed;
}
// Update is called once per frame
void Update () {
GunShoot();
GunReload ();
}
void GunShoot(){
if (Input.GetKeyDown (KeyCode.Mouse0) && CurAmmoAmount > 0 && canReload == false) {
CurAmmoAmount--;
audio.PlayOneShot(Shotsound);
}
}
void GunReload(){
if(Input.GetKeyDown(KeyCode.R) || CurAmmoAmount <= 0){
canReload = true;
audio.PlayOneShot(Chargersound);
}
if(canReload){
reloadSpeedModifier -= Time.deltaTime;
if(didplayerreloadinganim == false){
MagazineGB.animation.Play("animation ak47");
audio.PlayOneShot(Chargersound);
didplayerreloadinganim = true;
}
if(MaxAmmoAmount > 30 && reloadSpeedModifier <= 0){
CurAmmoAmount = 30;
MaxAmmoAmount -= 30;
(GetComponent("oplayershoot") as MonoBehaviour).enabled = false;
reloadSpeedModifier = ReloadSpeed;
canReload = false;
didplayerreloadinganim = false;
}else if(MaxAmmoAmount < 30 && reloadSpeedModifier <= 0){
CurAmmoAmount = MaxAmmoAmount;
MaxAmmoAmount = 0;
(GetComponent("oplayershoot") as MonoBehaviour).enabled = true;
reloadSpeedModifier = ReloadSpeed;
canReload = false;
didplayerreloadinganim = false;
}
}
}
void OnGUI(){
GUI.Label (new Rect (130, Screen.height - 75, 60, 30), CurAmmoAmount.ToString () + "/" + MaxAmmoAmount.ToString ());
int index = 1;
while (index <= CurAmmoAmount) {
index++;
GUI.DrawTexture(new Rect( (index * 9), Screen.height - 55, 42, 50), AmmoGUI);
}
}
}
Comment