要用一個空物件包住player
var MyBody : GameObject ;
var Run : boolean;
var speed : float;
function Update () {
if (Input.GetKey (KeyCode.W)){
MyBody.gameObject.GetComponent(Body).Run=true;
this.transform.Translate(0.0,0.0,speed*Time.deltaTime,Space.Self);
}else{
MyBody.gameObject.GetComponent(Body).Run=false; //後面的body是scp名稱,前面的MyBody是空物件的名稱
}
}
------------------------------ (放入空物件裡的player模型)
var Run:boolean;
var Walk : boolean;
var Am: Animator ;
function Start(){
Am = this.gameObject.GetComponent(Animator);
}
function Update(){
Am.SetBool("Walk",Walk);
Am.SetBool("Run",Run);
}
----------------------------------------------------------------------------------------
- Jan 20 Tue 2015 09:17
Animator .GetComponent
close
全站熱搜
留言列表