unity中多个门的开关动画保持独立性

Posted 不积跬步,无以至千里;不积小流,无以成江海。任何业绩的质变都

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了unity中多个门的开关动画保持独立性相关的知识,希望对你有一定的参考价值。

 List<Animation> storeAnimation;
public void Awake()
{ storeAnimation
= new List<Animation>(); storeAnimation.Clear(); } private void Update() {     //1. 获取鼠标点击位置 //创建射线;从摄像机发射一条经过鼠标当前位置的射线   Ray ray = firstCamera.ScreenPointToRay(Input.mousePosition); //发射射线 RaycastHit hitInfo = new RaycastHit(); if (Physics.Raycast(ray, out hitInfo)) { if (hitInfo.collider.name == "plantLeftDoor01" || hitInfo.collider.name == "plantLeftDoor02" || hitInfo.collider.name == "plantLeftDoor03" || hitInfo.collider.name == "plantLeftDoor04" || hitInfo.collider.name == "plantLeftDoor05" || hitInfo.collider.name == "plantLeftDoor06" || hitInfo.collider.name == "plantLeftDoor07" || hitInfo.collider.name == "plantLeftDoor08") { OpenOrCloseLeftDoor(hitInfo); } else if (hitInfo.collider.name == "plantRightDoor01" || hitInfo.collider.name == "plantRightDoor02" || hitInfo.collider.name == "plantRightDoor03" || hitInfo.collider.name == "plantRightDoor04" || hitInfo.collider.name == "plantRightDoor05" || hitInfo.collider.name == "plantRightDoor06" || hitInfo.collider.name == "plantRightDoor07" || hitInfo.collider.name == "plantRightDoor08") { OpenOrCloseRightDoor(hitInfo); } } } private void OpenOrCloseLeftDoor(RaycastHit hitInfo) { leftAnim = hitInfo.collider.transform.GetComponent<Animation>(); if (!storeAnimation.Contains(leftAnim))//说明第一次点击 { leftAnim["leftDoor"].speed = 1; leftAnim.Play("leftDoor"); storeAnimation.Add(leftAnim); } else { leftAnim["leftDoor"].time = leftAnim["leftDoor"].length; leftAnim["leftDoor"].speed = -1; leftAnim.Play("leftDoor"); storeAnimation.Remove(leftAnim); } } private void OpenOrCloseRightDoor(RaycastHit hitInfo) { rightAnim = hitInfo.collider.transform.GetComponent<Animation>(); if (!storeAnimation.Contains(rightAnim))//说明第一次点击 { rightAnim["rightDoor"].speed = 1; rightAnim.Play("rightDoor"); storeAnimation.Add(rightAnim); } else { rightAnim["rightDoor"].time = rightAnim["rightDoor"].length; rightAnim["rightDoor"].speed = -1; rightAnim.Play("rightDoor"); storeAnimation.Remove(rightAnim); } }

 

以上是关于unity中多个门的开关动画保持独立性的主要内容,如果未能解决你的问题,请参考以下文章

Unity -- Animation(旧版动画组件)和Animator(新版动画器组件)

Maya 创建多个模型动画并导出到Unity 流程

Unity中获取Animator中动画片段的时长

unity 5.6 animation与anmimator

ViewPager开关没有显示片段之间

Mecanim 动画系统(第二部分)