Unity3d 开门的javascript脚本

使用方法,做一个门,把注册点放到一边的中间,做一个Trigger,把脚本拖到trigger里面,再把Door赋值给door,然后就能使用了。

#pragma strict
var door:Transform;
var opendoor =false;
var door_time:float=0;
var open_sound:AudioClip;
function OnTriggerStay(other:Collider){
 door_time +=Time.deltaTime;
 //print(door_time);
 if(Input.GetKey(KeyCode.E)&&door_time>=1){
  door.audio.PlayOneShot(open_sound);
  if(opendoor == false){
   opendoor = true;
   door_time =0;
  }
  else{
   opendoor = false;
   door_time =0;
  }
 }
 if(opendoor){
 if(door.transform.eulerAngles.y<90){
    door.transform.eulerAngles.y+=2;
 }
 }
 if(opendoor==false){
 if(door.transform.eulerAngles.y>10){
    door.transform.eulerAngles.y-=2;
 }
 }
}


你可能感兴趣的:(Unity3d)