1.先手动操作animation开门和关门动画,生成自动门的移动动画
2.新建脚本Door.cs负载在门Door上。
在Door上新建组件animation
public class Door : MonoBehaviour
{
// private Transform door_transform;
private Animation animation;
// Start is called before the first frame update
void Start()
{
// door_transform = gameObject.GetComponent();
animation = gameObject.GetComponent();
// animation["OpenDoorAni"].time = animation["OpenDoorAni"].clip.length;
}
void OnTriggerEnter(Collider coll)
{
if (coll.gameObject.name == "Student")
{
animation.Play("OpenDoorAni");
}
}
void OnTriggerExit(Collider coll)
{
if (coll.gameObject.name == "Student")
{
animation.Play("CloseDoorAni");
}
}
}


![[Unity3D]使用碰撞体触发器实现自动开门 [Unity3D]使用碰撞体触发器实现自动开门](http://www.mshxw.com/aiimages/31/900708.png)
