1、var sliderValue = 1.0;//定义动画速度var animationspeed = 0.5;//定义两组动画段的名字(这里要事先在max里做好两组动画,导入时设置一下起止时间)
2、var clip1 : String = "clip1";var clip2 : String = "clip2";//定义要做运动的物体的标签var touchableTag1 : String = "";//记录开关状态的参数var animationed1 : boolean = false;//刷帧函数要检测当左键按下时,做哪个动画段
3、function Update () {//以下为点击物体的固定模式,记住就好var ray = Camera.main.ScreenPointToRay(Input.mousePosition);var hit : RaycastHit;//当按下左键,并且门为关时,运行开函数,否则运行关函数
4、if (Physics.Raycast(ray,hit) && Input.GetMouseButtonDown(0) ){if (animationed1 == false){if (hit.transform.gameObject.CompareTag(touchableTag1))actionrun();}else if (animationed1 == true){if (hit.transform.gameObject.CompareTag(touchableTag1))actionrun _ fan();}}}
5、//开门动画function actionrun() : boolean{animation.Play(clip2);animation[clip2].speed = animationspeed;animationed1 = true;//要改变门的状态为开哦}//反向开门动画(倒放)function actionrun _ fan() : boolean{animation.Play(clip2);animation[clip2].speed = animationspeed * -1.0;animationed1 = false;//要改变门的状态为关哦}