Assignment for RMIT Mixed Reality in 2020
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.

64 lines
1.4 KiB

  1. namespace Oculus.Platform.Samples.VrHoops
  2. {
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. // Uses two triggers to detect that a basket is made by traveling from top to bottom
  6. // through the hoop.
  7. public class DetectBasket : MonoBehaviour
  8. {
  9. private enum BasketPhase { NONE, TOP, BOTH, BOTTOM }
  10. private BasketPhase m_phase = BasketPhase.NONE;
  11. private Player m_owningPlayer;
  12. public Player Player
  13. {
  14. set { m_owningPlayer = value; }
  15. }
  16. void OnTriggerEnter(Collider other)
  17. {
  18. if (other.gameObject.name == "Basket Top" && m_phase == BasketPhase.NONE)
  19. {
  20. m_phase = BasketPhase.TOP;
  21. }
  22. else if (other.gameObject.name == "Basket Bottom" && m_phase == BasketPhase.TOP)
  23. {
  24. m_phase = BasketPhase.BOTH;
  25. }
  26. else
  27. {
  28. m_phase = BasketPhase.NONE;
  29. }
  30. }
  31. void OnTriggerExit(Collider other)
  32. {
  33. if (other.gameObject.name == "Basket Top" && m_phase == BasketPhase.BOTH)
  34. {
  35. m_phase = BasketPhase.BOTTOM;
  36. }
  37. else if (other.gameObject.name == "Basket Bottom" && m_phase == BasketPhase.BOTTOM)
  38. {
  39. m_phase = BasketPhase.NONE;
  40. switch (PlatformManager.CurrentState)
  41. {
  42. case PlatformManager.State.PLAYING_A_LOCAL_MATCH:
  43. case PlatformManager.State.PLAYING_A_NETWORKED_MATCH:
  44. if (m_owningPlayer)
  45. {
  46. m_owningPlayer.Score += 2;
  47. }
  48. break;
  49. }
  50. }
  51. else
  52. {
  53. m_phase = BasketPhase.NONE;
  54. }
  55. }
  56. }
  57. }