Teachers open the door but You must enter by yourself.
using UnityEngine;
using UnityEngine.InputSystem;
public class Bow : MonoBehaviour
{
void Start()
{
var a=new InputSystem_Actions();
a.Enable();
a.Player.Sprint.performed+=OnFire;
}
void Update()
{
}
void OnFire(InputAction.CallbackContext c)//右トリガーが引かれると実行
{
Debug.Log("fire");
}
}
using UnityEngine;
using UnityEngine.InputSystem;
public class Bow : MonoBehaviour
{
public GameObject leftController;
public GameObject rightController;
enum State{Idle, Pull, Ready}
public State state;
void Start()
{
var a=new InputSystem_Actions();
a.Enable();
a.Player.Sprint.performed+=OnFire;
state=State.Idle;
}
void Update()
{
float d=Vector3.Distance(
leftController.transform.position,
rightController.transform.position
);
//Debug.Log(d);
switch(state){
case State.Idle:
if(d<0.4f) state=State.Pull;
break;
case State.Pull:
if(d>0.4f){
GetComponent<Animation>().Play("BowPullAnimation");
state=State.Ready;
}
break;
}
}
void OnFire(InputAction.CallbackContext c){
Debug.Log("fire");
if(state==State.Ready){
GetComponent<Animation>().Play("BowReleaseAnimation");
state=State.Idle;
}
}
}