Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

Display gun Ammo onsceen

$
0
0
i have my gun and my gun script (C#) and it has 30 rounds per clip, it reloads fine but i want a GUI onscreen to display the ammo, also if you could add a limit to amount of clips i could have just like the amount of bullets per clip that would be great but my main goal is the AMMO gui here it is: using UnityEngine; using System.Collections; using UltraReal.Utilities; using UltraReal.WeaponSystem; /// /// Basic launcher class. This would be your gun script. /// public class BasicLauncher : UltraRealLauncherBase { /// /// Time before the next shot can be fired. /// float _nextShotTime; /// /// keeps track of the current ammo count before a reload is requred. /// int _ammoCount; int _clipCount; /// /// Time delay before next shot can be fired. A machine gun would use a really small shot delay. /// [SerializeField] private float _shotDelay = 0.1f; /// /// How long it takes to reload the wepaon. /// [SerializeField] private float _reloadDelay = 1f; /// /// The amount of ammo a magazine(clip) can hold. /// [SerializeField] private int _magazineSize = 20; /// /// Reference to the Transform for the shell ejector. /// [SerializeField] private Transform _ejectorTransform = null; /// /// Reference to the Transform for the muzzle position. /// [SerializeField] private Transform _muzzleTransform = null; /// /// Reference to the AudoClip for reloading. /// [SerializeField] private AudioClip _reloadSound = null; /// /// Reference to the AudoClip for missfiring. /// [SerializeField] private AudioClip _missfireSound = null; /// /// Force applied to ejected shells. /// [SerializeField] protected float _ejectorForce = 100f; /// /// Torque applied to ejected shells. /// [SerializeField] protected float _ejectorTorque = 100f; /// /// Reference to the AudioSource for the gun. If it's null, it will create one. /// [SerializeField] protected AudioSource _audioSource = null; /// /// Reference to animator for the shooting, and reloading /// [SerializeField] protected Animator _animator = null; /// /// Name of the trigger in the animation controller for Firing. /// [SerializeField] protected string _fireAnimTriggerName = "Fire"; /// /// Name of the trigger in the animation controller for Reloading. /// [SerializeField] protected string _reloadAnimTriggerName = "Reload"; /// /// Sets defaults for weapon /// protected override void OnStart () { base.OnStart (); _nextShotTime = Time.time; _ammoCount = _magazineSize; if (_audioSource == null) _audioSource = gameObject.AddComponent(); } /// /// Fires the weapon /// public override void Fire () { if (_nextShotTime <= Time.time){ if (_ammoCount > 0 && _ammo != null) { if(_muzzleTransform != null) _ammo.SpawnAmmo(_muzzleTransform, _ejectorTransform, _ejectorForce, _ejectorTorque, 2f, _audioSource); _ammoCount--; if (_animator != null) _animator.SetTrigger(_fireAnimTriggerName); base.Fire (); } else MissFire(); _nextShotTime = Time.time + _shotDelay; } } /// /// Forces a weapon missfire. /// public override void MissFire() { base.MissFire (); if (_missfireSound != null && _audioSource != null) _audioSource.PlayOneShot (_missfireSound); } /// /// Reloads the weapon /// public override void Reload () { base.Reload (); if (_reloadSound != null && _audioSource != null) _audioSource.PlayOneShot (_reloadSound); if (_animator != null) _animator.SetTrigger(_reloadAnimTriggerName); _nextShotTime = Time.time + _reloadDelay; _ammoCount = _magazineSize; } }

Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>