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