UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"gun reload"
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Reload : MonoBehaviour { void Update() { if (Clipammo != 0 && isReloading == false) { canFire = true; } if (Input.GetKeyDown(KeyCode.Mouse0) && canFire && !t$$anonymous$$s.tag.Contains("Auto")) { Clipammo--; } if (Input.GetKey(KeyCode.Mouse0) && canFire && t$$anonymous$$s.tag.Contains("Auto")) { Clipammo--; } if (Input.GetKeyDown("r") && !isReloading) { isReloading = true; StartCoroutine(ReloadDelay()); } if (Clipammo < 0) Clipammo = 0; canFire = false; if (ammo < 0) ammo = 0; } IEnumerator ReloadDelay() { yield return new WaitForSeconds(3); if (ammo > Clipsize - Clipammo) { Rammo = Clipsize - Clipammo; Clipammo = Clipsize; ammo = ammo - Rammo; } else { Rammo = Clipsize - Clipammo; Clipammo = Clipammo + ammo; ammo = 0; } isReloading = false; canFire = true; } }