|
Post by sickscore on Aug 29, 2017 21:04:04 GMT
INFINITE AMMO EASY WAY TO NOT CONSUME AMMO ON YOUR WEAPON
Hey guys,
just sharing a little code snipped I used for an upcoming addon. Just add the script to any shooter weapon and it will not consume ammo! It's really simple code, but maybe someone needs this feature aswell.
Cheers, sickscore vInfiniteAmmo.csusing System.Collections; using System.Collections.Generic; using UnityEngine; using Sickscore;
namespace Sickscore.ShooterAddons { [RequireComponent(typeof(vShooterWeapon))] public class vInfiniteAmmo : MonoBehaviour { #region Variables protected vShooterWeapon ShooterWeapon; #endregion
#region Main Methods void Awake () { ShooterWeapon = GetComponent<vShooterWeapon> (); ShooterWeapon.onShot.AddListener (AddBulletOnShot); }
void OnDisable () { ShooterWeapon.onShot.RemoveListener (AddBulletOnShot); } #endregion
#region Utility Methods void AddBulletOnShot () { ShooterWeapon.AddAmmo (1); } #endregion } }
|
|
|
Post by orionuk on Sept 30, 2017 21:40:42 GMT
Hey SickScore, Cheers very much mate
|
|
frax
Junior vMember
Posts: 27
|
Post by frax on Nov 9, 2017 14:33:54 GMT
Hello. How i can fix this?
Can't remove vShooterWeapon (Script) because vInfiniteAmmo (Script) depends on it
|
|
|
Post by tharindu on Nov 9, 2017 15:36:22 GMT
Hello. How i can fix this? Can't remove vShooterWeapon (Script) because vInfiniteAmmo (Script) depends on it Does this occur when you're trying to switch weapons or something ?
|
|
frax
Junior vMember
Posts: 27
|
Post by frax on Nov 9, 2017 19:40:23 GMT
its happens in when character die and respawn
|
|
|
Post by tharindu on Nov 9, 2017 19:43:27 GMT
Well until sickscore gets back with a better solution I guess you can remove the [RequireComponent(typeof(vShooterWeapon))] part from the ammo script.
The problem I am assuming is when the player is getting killed the weapon is being destroyed before the infinite ammo script, which is causing issues as the weapon is required for the ammo script to run.
|
|
|
Post by sickscore on Nov 9, 2017 20:57:28 GMT
I think you can just remove the line and check for the shooter weapon component. Will look at it tomorrow ;-)
|
|