Main.csに以下のスクリプトを追記
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class Main : MonoBehaviour
{
void Awake(){
XRIDefaultInputActions inputActions=new XRIDefaultInputActions();
inputActions.Enable();
inputActions.XRIRightHandInteraction.Activate.performed+=OnActivate;
}
Transform leftHand,rightHand;
enum State{Idle, Pull, Ready}
State state=State.Idle;
void Start(){
GameObject.Find("/Horse").GetComponent<Horse>().Run();
leftHand=GameObject.Find("Left Controller").transform;
rightHand=GameObject.Find("Right Controller").transform;
}
void Update()
{
float d=Vector3.Distance(leftHand.position, rightHand.position);
Debug.Log(d);
switch(state){
case State.Idle:
if(d<0.4f) state=State.Pull;
break;
case State.Pull:
if(d>0.4f){
GameObject.Find("Bow").GetComponent<Animation>().Play("BowPullAnimation");
state=State.Ready;
}
break;
}
}
void OnActivate(InputAction.CallbackContext context){
if(state==State.Ready){
GameObject.Find("Bow").GetComponent<Animation>().Play("BowReleaseAnimation");
state=State.Idle;
}
}
}