Teachers open the door but You must enter by yourself.

Open Media Lab.
オープンメディアラボ

矢のセットアップ

  1. 矢にRigidbodyコンポーネントを追加し、Use Gravity のチェックを外す
  2. Capsule Collider を追加し、Radius=0.03、Height=0.8、Is Trigger にチェックを付ける
  3. 矢の機能を呈するスクリプト Arrow.cs を作成し、Arrow にアタッチ
    
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Arrow : MonoBehaviour
    {
      	public float groundSpeed=7.5f;//馬の速度
    	public float launchSpeed=10f;
    	public float magnify=2f;
    
    	bool flying=false;
    
    	float launched;    
    	public void Ready(){
    		transform.parent=GameObject.Find("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>().velocity=Vector3.zero;
    		flying=false;
    	}
    
    	public void Fire(){
    		transform.parent=null;
    		GetComponent<Rigidbody>().velocity=Vector3.forward*groundSpeed + transform.up*launchSpeed;
    		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);
    			}
    		}
    	}
    }
    
  4. Main.cs の Update()、OnActivate() に以下のスクリプトを追記
    
    	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");
    					GameObject.Find("Arrow").GetComponent<Arrow>().Ready();
    					state=State.Ready;
    				}
    				break;
    		}
    	}
    
    	void OnActivate(InputAction.CallbackContext context){
    		if(state==State.Ready){
    			GameObject.Find("Bow").GetComponent<Animation>().Play("BowReleaseAnimation");
    			GameObject.Find("Arrow").GetComponent<Arrow>().Fire();
    			state=State.Idle;
    		}
    	}
    

    This site is powered by Powered by MathJax