Teachers open the door but You must enter by yourself.
using UnityEngine;
using UnityEngine.InputSystem;
public class Bow : MonoBehaviour
{
public InputAction trigger;
void OnFire(InputAction.CallbackContext c)
{
//発射の処理を記述
Debug.Log("fire");
}
void Awake(){
trigger.performed+=OnFire;
}
void OnEnable(){
trigger.Enable();
}
}
using UnityEngine;
using UnityEngine.InputSystem;
public class Bow : MonoBehaviour
{
public InputAction trigger;
public Transform leftController;
public Transform rightController;
enum State{Idle, Grab, Pull}
State state=State.Idle;
float Distance=>Vector3.Distance(leftController.position, rightController.position);
void Update()
{
switch(state){
case State.Idle:
if(Distance<0.4f){
state=State.Grab;
}
break;
case State.Grab:
if(Distance>0.4f){
GetComponent<Animation>().Play("BowPullAnimation");
state=State.Pull;
}
break;
}
// Debug.Log(Distance);
}
void OnFire(InputAction.CallbackContext c){
if(state==State.Pull){
//弦を離す処理を記述
}
Debug.Log("fire");
}
・・・
}