Teachers open the door but You must enter by yourself.

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

馬のセットアップ

馬をスタート位置に配置

  1. Position を(0,0,300)に設定
  2. Box Colliderは不要なのでチェックを外す

プレーヤーの視点位置の調整

  1. XR Origin (VR) を Hourse の子に移動 Position をリセット
  2. 再生して XR Origin (VR) の位置を調整し、調整後の Position の値をコピー
  3. 再生を停止して XR Origin (VR) の Position に値をペースト

馬の走行

  1. 馬の機能を呈するスクリプト Horse.cs を作成し、Horse にアタッチ、VRで動作を確認する。
    
    using UnityEngine;
    
    public class Horse : MonoBehaviour
    {
    	public bool running; //馬が走行中 true、停止中 false
    
    	void Start(){
    		GetComponent<Horse>().Run();
    	}
    
    	public void Run(){ //馬が走る動作のアニメーションを開始
    		GetComponent<Animator>().SetTrigger("run");
    		running = true;
    	}
    
    	public void Stop(){ //馬が走る動作のアニメーションを停止
    		GetComponent<Animator>().SetTrigger("stop");
    		running = false;
    	}
    }	
    
  2. 馬を前に進める処理(赤字の部分)を追加し、VRで動作を確認する。
    
    using UnityEngine;
    
    public class Horse : MonoBehaviour
    {
    	public bool running;
    	public float velocity=7.5f; //馬の速度
    
    	void Start(){
    		GetComponent<Horse>().Run();
    	}
    
    	void Update(){
    		if(running){//馬が走行中なら、速度と経過時間の分、馬をz軸の正方向に進める
    			GetComponent<CharacterController>().Move(Vector3.forward*velocity*Time.deltaTime);
    		}
    	}
    
    	public void Run(){
    		GetComponent<Animator>().SetTrigger("run");
    		running = true;
    	}
    
    	public void Stop(){
    		GetComponent<Animator>().SetTrigger("stop");
    		running = false;
    	}
    }	
    
This site is powered by
Powered by MathJax