Global Game Jam 2023
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
2.3 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using NaughtyAttributes;
  5. using Unity.VisualScripting;
  6. using UnityEngine.Events;
  7. /// <summary>
  8. ///
  9. /// </summary>
  10. public class BoatRowController : MonoBehaviour
  11. {
  12. #region Inspector Fields
  13. public Transform m_oarTip;
  14. public UnityEvent m_OnRow;
  15. #endregion Inspector Fields
  16. #region Private Fields
  17. private Vector3 m_lastKnownOarPosition;
  18. #endregion Private Fields
  19. #region Getters
  20. #endregion Getters
  21. #region MonoBehaviour Functions
  22. /// <summary>
  23. /// OnEnable is called when the object becomes enabled and active.
  24. /// </summary>
  25. private void OnEnable()
  26. {
  27. }
  28. /// <summary>
  29. /// OnDisable is called when the behaviour becomes disabled.
  30. /// </summary>
  31. private void OnDisable()
  32. {
  33. }
  34. /// <summary>
  35. /// Update is called once per frame
  36. /// </summary>
  37. private void Update()
  38. {
  39. }
  40. #endregion MonoBehaviour Functions
  41. #region Class Functionality
  42. private void OnTriggerEnter(Collider other)
  43. {
  44. OarController oar = other.GetComponentInParent<OarController>();
  45. if (oar != null)
  46. {
  47. m_lastKnownOarPosition = m_oarTip.position;
  48. }
  49. }
  50. void OnTriggerStay(Collider other)
  51. {
  52. OarController oar = other.GetComponentInParent<OarController>();
  53. if(oar != null)
  54. {
  55. Vector3 direction = m_lastKnownOarPosition - m_oarTip.position;
  56. direction = Vector3.Project(direction,transform.forward);
  57. float directionality = Vector3.Dot(direction,transform.forward);
  58. if (directionality > 0)
  59. {
  60. // Debug.Log($"Row! ({directionality})");
  61. m_OnRow.Invoke();
  62. }
  63. else
  64. {
  65. // Debug.Log($"No Row: {directionality}");
  66. }
  67. m_lastKnownOarPosition=m_oarTip.position;
  68. }
  69. else
  70. {
  71. // Debug.Log($"Not Oar: {other.gameObject}");
  72. }
  73. }
  74. #endregion Class Functionality
  75. #region Editor Functions
  76. /// <summary>
  77. /// Called when the Component is created or Reset from the Inspector
  78. /// </summary>
  79. private void Reset()
  80. {
  81. //useful for finding components on creation
  82. }
  83. #endregion Editor Functions
  84. }