Teachers open the door but You must enter by yourself.
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;
}
}
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;
}
}