UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"gun change with mouse wheel"
using UnityEngine; using System.Collections; public class GunSelection : MonoBehaviour { public void SwitchGunByMouse(float direction) { if (gunsAvailable.Count <= 1 || cannotChangeWeapon) { return; } int gunSwitchDirection = Mathf.Sign(direction); int gunCandidate = currentGun; bool isCorrect = false; do { gunCandidate += gunSwitchDirection; if (gunCandidate < 0) { gunCandidate = allGuns.Count -1; } else { gunCandidate %= allGuns.Count; } isCorrect = gunCandidate != currentGun && unlockedGuns[gunCandidate]; } while (gunCandidate==currentGun || !unlockedGuns[gunCandidate]); SwitchGun(gunCandidate); } }