65 lines
1.3 KiB
C#
65 lines
1.3 KiB
C#
using UnityEngine;
|
|
|
|
namespace Oculus.Platform.Samples.VrHoops
|
|
{
|
|
public class DetectBasket : MonoBehaviour
|
|
{
|
|
private enum BasketPhase
|
|
{
|
|
NONE = 0,
|
|
TOP = 1,
|
|
BOTH = 2,
|
|
BOTTOM = 3
|
|
}
|
|
|
|
private BasketPhase m_phase;
|
|
|
|
private Player m_owningPlayer;
|
|
|
|
public Player Player
|
|
{
|
|
set
|
|
{
|
|
m_owningPlayer = value;
|
|
}
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.gameObject.name == "Basket Top" && m_phase == BasketPhase.NONE)
|
|
{
|
|
m_phase = BasketPhase.TOP;
|
|
}
|
|
else if (other.gameObject.name == "Basket Bottom" && m_phase == BasketPhase.TOP)
|
|
{
|
|
m_phase = BasketPhase.BOTH;
|
|
}
|
|
else
|
|
{
|
|
m_phase = BasketPhase.NONE;
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
if (other.gameObject.name == "Basket Top" && m_phase == BasketPhase.BOTH)
|
|
{
|
|
m_phase = BasketPhase.BOTTOM;
|
|
}
|
|
else if (other.gameObject.name == "Basket Bottom" && m_phase == BasketPhase.BOTTOM)
|
|
{
|
|
m_phase = BasketPhase.NONE;
|
|
PlatformManager.State currentState = PlatformManager.CurrentState;
|
|
if ((currentState == PlatformManager.State.PLAYING_A_LOCAL_MATCH || currentState == PlatformManager.State.PLAYING_A_NETWORKED_MATCH) && (bool)m_owningPlayer)
|
|
{
|
|
m_owningPlayer.Score += 2u;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m_phase = BasketPhase.NONE;
|
|
}
|
|
}
|
|
}
|
|
}
|