[RequireComponent(typeof(ShootableWeapon))]
public class ShootableWeaponUccMakeNoise : MonoBehaviour
{
private GameObject m_Character;
private IUsableItem _usableItem;
private void Awake()
{
var characterLocomotion = gameObject.GetCachedParentComponent<UltimateCharacterLocomotion>();
m_Character = characterLocomotion.gameObject;
_usableItem = GetComponent<IUsableItem>();
}
private void OnEnable()
{
EventHandler.RegisterEvent<IUsableItem, bool>(m_Character, "OnItemStartUse", ItemStartUse);
}
private void ItemStartUse(IUsableItem usableItem, bool isStart)
{
if (isStart && _usableItem == usableItem)
{
Debug.Log("shot: " + _usableItem);
}
}
private void OnDisable()
{
EventHandler.UnregisterEvent<IUsableItem, bool>(m_Character, "OnItemStartUse", ItemStartUse);
}
}
This is working great, @Absent83 how would you change the code to register the stop event too?Hi, are you sure?
I add this component to all shootableItems and it works good!
please review this code
C#:[RequireComponent(typeof(ShootableWeapon))] public class ShootableWeaponUccMakeNoise : MonoBehaviour { private GameObject m_Character; private IUsableItem _usableItem; private void Awake() { var characterLocomotion = gameObject.GetCachedParentComponent<UltimateCharacterLocomotion>(); m_Character = characterLocomotion.gameObject; _usableItem = GetComponent<IUsableItem>(); } private void OnEnable() { EventHandler.RegisterEvent<IUsableItem, bool>(m_Character, "OnItemStartUse", ItemStartUse); } private void ItemStartUse(IUsableItem usableItem, bool isStart) { if (isStart && _usableItem == usableItem) { Debug.Log("shot: " + _usableItem); } } private void OnDisable() { EventHandler.UnregisterEvent<IUsableItem, bool>(m_Character, "OnItemStartUse", ItemStartUse); } }