- Home /
Need Help With a Gun Reloaded script pls help?
I want my Reload whenever i press r And here is the script In c#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HandGunReloading : MonoBehaviour {
public AudioSource ReloadSound;
public GameObject CrossObject;
public GameObject MechanicsObject;
public int ClipCount;
public int ReserveCount;
public int ReloadAvailable;
public GunFire GunComponent;
void Start () { GunComponent = GetComponent(); }
void Update () {
ClipCount = GlobelAmmo.LoadedAmmo;
ReserveCount = GlobelAmmo.CurrentAmmo;
if (ReserveCount == 0) {
ReloadAvailable = 0; } else { ReloadAvailable = 10 - ClipCount; }
if(Input.GetButtonDown("Reload")) {
if (ReloadAvailable >= 1) {
if (ReserveCount <= ReloadAvailable) {
GlobelAmmo.LoadedAmmo += ReserveCount;
GlobelAmmo.CurrentAmmo -= ReserveCount;
ActionReload();
} else { GlobelAmmo.LoadedAmmo += ReloadAvailable; GlobelAmmo.CurrentAmmo -= ReloadAvailable; ActionReload(); } } StartCoroutine(EnableScripts());
} }
IEnumerator EnableScripts () { yield return new WaitForSeconds (1.1f); GunComponent.enabled=true; CrossObject.SetActive(true); MechanicsObject.SetActive(true); }
void ActionReload () {
GunComponent.enabled=false;
CrossObject.SetActive(false);
MechanicsObject.SetActive(false);
ReloadSound.Play();
GetComponent().Play("HandgunReload"); } }
Any Help apreciated
Could you please format your code better? It's a little unreadable. Thanks.
Your answer
Follow this Question
Related Questions
Renderer on object disabled after level reload 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Reload clips on Gun-script not applied properly 1 Answer
separate script to reload. 0 Answers