-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6bb7a06
commit fef118b
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |