MeleeWeapon.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using UnityEngine;
  2. namespace Assets.HeroEditor4D.Common.Scripts.CharacterScripts
  3. {
  4. /// <summary>
  5. /// General melee weapon behaviour.
  6. /// First thing you need to check is hit event. Use animation events or check user input.
  7. /// Second thing is to resolve impacts to other objects (enemies, environment). Use collisions or raycasts.
  8. /// </summary>
  9. public class MeleeWeapon : MonoBehaviour
  10. {
  11. public AnimationEvents AnimationEvents;
  12. public Transform Edge;
  13. /// <summary>
  14. /// Listen animation events to determine hit moments.
  15. /// </summary>
  16. public void Start()
  17. {
  18. AnimationEvents.OnEvent += OnAnimationEvent;
  19. }
  20. public void OnDestroy()
  21. {
  22. AnimationEvents.OnEvent -= OnAnimationEvent;
  23. }
  24. private void OnAnimationEvent(string eventName)
  25. {
  26. switch (eventName)
  27. {
  28. case "Hit":
  29. // Place hit behaviour here. For example, you could check/raycast collisions here.
  30. break;
  31. default: return;
  32. }
  33. }
  34. }
  35. }