首页 > 编程语言 > 详细

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

时间:2018-03-30 20:32:35      阅读:267      评论:0      收藏:0      [点我收藏+]
 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中多个门的开关动画保持独立性

原文:https://www.cnblogs.com/Study088/p/8678265.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!