Teachers open the door but You must enter by yourself.
using UnityEngine;
public class Arrow : MonoBehaviour
{
public float groundSpeed=7.5f;//馬の速度
public float launchSpeed=10f;
public float magnify=2f;
public GameObject bow;
bool flying=false;
float launched;
public void Ready(){
transform.parent=bow.transform;
transform.localPosition=new Vector3(0, 0, -0.3f);
transform.localRotation=Quaternion.Euler(90f, 0f, 0f);
transform.localScale=new Vector3(1f, 1f, 1f);
GetComponent<Rigidbody>().linearVelocity=Vector3.zero;
flying=false;
}
public void Fire(){
var v=Vector3.forward*groundSpeed + transform.up*launchSpeed;
GetComponent<Rigidbody>().linearVelocity=v;
transform.parent=null;
launched=Time.time;
flying=true;
}
void Update()
{
if(flying){
var flyingTime=Time.time-launched;
if(flyingTime>3f){
Ready();
}else{
var scale = 1f + magnify*flyingTime;
transform.localScale=new Vector3(scale, scale, scale);
}
}
}
}
using UnityEngine;
using UnityEngine.InputSystem;
public class Bow : MonoBehaviour
{
public GameObject leftController;
public GameObject rightController;
public GameObject arrow;
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");
arrow.GetComponent<Arrow>().Ready();
state=State.Ready;
}
break;
}
}
void OnFire(InputAction.CallbackContext c){
Debug.Log("fire");
if(state==State.Ready){
GetComponent<Animation>().Play("BowReleaseAnimation");
arrow.GetComponent<Arrow>().Fire();
state=State.Idle;
}
}
}