-
Notifications
You must be signed in to change notification settings - Fork 77
/
WeaponAutoDestroyWhenEmpty.cs
32 lines (31 loc) · 1.29 KB
/
WeaponAutoDestroyWhenEmpty.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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;
}
}
}