[Unity3D]使⽤碰撞体触发器实现⾃动开门1.先⼿动操作animation开门和关门动画,⽣成⾃动门的移动动画
2.新建脚本Door.cs负载在门Door上。
unity3d animation
在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<Transform>();
animation = gameObject.GetComponent<Animation>();
//  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");
}
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。