• 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); } }
  • 相关阅读:
    table 如何不越过父级div
    sqlite3_column_type 与 SQLITE_NULL的区别
    lua 协程的理解
    linux 信号
    linux 查看文件夹大小
    linux 僵屍进程
    软件架构的理解
    jquery正则表达式
    linux C遍历目录下文件
    linux 进程间同步互斥
  • 原文地址:https://www.cnblogs.com/Study088/p/8678265.html
Copyright © 2020-2023  润新知