forked from cgvr/DeltaVR
replaced demo boxes with microphone stand and buttons, in archery range
This commit is contained in:
52
Assets/_PROJECT/Scripts/ModeGeneration/PushableButton.cs
Normal file
52
Assets/_PROJECT/Scripts/ModeGeneration/PushableButton.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
public class PushableButton : MonoBehaviour
|
||||
{
|
||||
public delegate void OnButtonPressedDelegate();
|
||||
public event OnButtonPressedDelegate OnButtonPressed;
|
||||
|
||||
|
||||
public Transform movableParts;
|
||||
public float moveDuration = 0.25f;
|
||||
|
||||
private float upPositionY;
|
||||
private float downPositionY;
|
||||
private bool isButtonDown;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
upPositionY = movableParts.localPosition.y;
|
||||
downPositionY = movableParts.localPosition.y - 0.1f;
|
||||
isButtonDown = false;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (!isButtonDown && collision.gameObject.tag.EndsWith("Hand"))
|
||||
{
|
||||
movableParts.DOLocalMoveY(downPositionY, moveDuration);
|
||||
isButtonDown = true;
|
||||
OnButtonPressed?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveButtonUp()
|
||||
{
|
||||
movableParts.DOLocalMoveY(upPositionY, moveDuration);
|
||||
isButtonDown = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user