Skip to content

Commit

Permalink
✨ Adds WeaponAutoDestroyWhenEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderGheorghe committed Mar 18, 2024
1 parent 6bb7a06 commit fef118b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ This repository contains community-created extensions for the TopDown Engine, Mo
* **TwinStickShooterHandleWeapon**, _by AlexanderGheorghe_ : an extension of CharacterHandleWeapon that gives you the option to shoot on receiving SecondaryMovement input, with configurable minimum magnitude of the input
* **TypedDamage**, _by AlexanderGheorghe_ : a collection of extension scripts that implement typed damage with scriptable objects, like explained in [this video](https://youtu.be/_q21rEaSlAs).
* **Vehicle**, _by AlexanderGheorghe_ : allows creating vehicles that the player character can enter, drive and exit. uses [Hayden Donnelly's Vehicle-Physics](https://github.com/hayden-donnelly/Vehicle-Physics).
* **WeaponAutoDestroyWhenEmpty**, _by AlexanderGheorghe_ : component that enables the Auto Destroy When Empty option to work without the Weapon Ammo component. goes on your magazine based, Auto Destroy When Empty weapon
* **WeaponCooldownProgressBar**, _by AlexanderGheorghe_ : put this component on a MMProgressBar and it will be updated with the weapon's cooldown progress
* **WeaponLaserSightEx**, _by Velsthinez_ : an extended version of the base WeaponLaserSight to create a widening laser when player turns

Expand Down
32 changes: 32 additions & 0 deletions WeaponAutoDestroyWhenEmpty/WeaponAutoDestroyWhenEmpty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using MoreMountains.Feedbacks;
using MoreMountains.TopDownEngine;
using UnityEngine;

[RequireComponent(typeof(Weapon))]
public class WeaponAutoDestroyWhenEmpty : MonoBehaviour
{
private Weapon[] _weapons;
[SerializeField] private MMFeedbacks DestructionStartFeedbacks;
private void Start()
{
_weapons = GetComponents<Weapon>();
if (!DestructionStartFeedbacks) return;
DestructionStartFeedbacks.Initialization();
#if UNITY_EDITOR
foreach (var weapon in _weapons)
if (weapon.AutoDestroyWhenEmpty && weapon.AutoDestroyWhenEmptyDelay < DestructionStartFeedbacks.TotalDuration)
Debug.LogWarning($"{name} {weapon.GetType().Name}'s Auto Destroy When Empty Delay is less than the Destruction Start Feedbacks total duration, {DestructionStartFeedbacks.TotalDuration:F}. Feedbacks may not play to the end", weapon);
#endif
}
private void Update()
{
foreach (var weapon in _weapons)
if (weapon.AutoDestroyWhenEmpty && weapon.CurrentAmmoLoaded < weapon.AmmoConsumedPerShot)
{
enabled = false;
DestructionStartFeedbacks?.PlayFeedbacks(transform.position);
StartCoroutine(weapon.WeaponDestruction());
break;
}
}
}

0 comments on commit fef118b

Please sign in to comment.