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.

107 lines
2.3 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  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.localPosition;
  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.localPosition;
  56. float directionality = Vector3.Dot(direction,Vector3.forward);
  57. if (directionality > 0)
  58. {
  59. Debug.Log($"Row! ({directionality})");
  60. m_OnRow.Invoke();
  61. }
  62. else
  63. {
  64. Debug.Log($"No Row: {directionality}");
  65. }
  66. m_lastKnownOarPosition=m_oarTip.localPosition;
  67. }
  68. else
  69. {
  70. Debug.Log($"Not Oar: {other.gameObject}");
  71. }
  72. }
  73. #endregion Class Functionality
  74. #region Editor Functions
  75. /// <summary>
  76. /// Called when the Component is created or Reset from the Inspector
  77. /// </summary>
  78. private void Reset()
  79. {
  80. //useful for finding components on creation
  81. }
  82. #endregion Editor Functions
  83. }