Ran*_*ith 1 c# animation unity-game-engine
我正在尝试在喷气发动机动画之间切换,但动画等待完成当前运行的动画,然后运行第二次单击的动画。有没有办法快进当前动画并立即切换到第二个。下面是喷气发动机对象的代码。
\n\nusing System.Collections;\nusing System.Collections.Generic;\nusing TMPro;\nusing UnityEngine;\n\npublic class mainScript : MonoBehaviour\n{\n\nAnimator first;\nbool firstTrig = false;\nbool secondTrig = false;\nbool thirdTrig = false;\nbool fourthTrig = false;\n\nstring temp = "";\nstring tempOld = "";\n\nprivate TMP_Text m_TextComponent;\nprivate bool hasTextChanged;\nint visibleCount = 0;\n\nvoid Awake()\n{\n ////m_TextComponent = gameObject.GetComponent<TMP_Text>();\n m_TextComponent = GameObject.Find("/information").GetComponent<TMP_Text>();\n}\n\nvoid OnEnable()\n{\n // Subscribe to event fired when text object has been regenerated.\n TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);\n}\n\nvoid OnDisable()\n{\n TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(ON_TEXT_CHANGED);\n}\n\n// Event received when the text object has changed.\nvoid ON_TEXT_CHANGED(Object obj)\n{\n hasTextChanged = true;\n}\n\n/* /// <summary> */\n/// Method revealing the text one character at a time.\n/// </summary>\n/// <returns></returns>\nIEnumerator RevealCharacters(TMP_Text textComponent)\n{\n textComponent.ForceMeshUpdate();\n\n TMP_TextInfo textInfo = textComponent.textInfo;\n\n int totalVisibleCharacters = textInfo.characterCount; // Get # of Visible Character in text object\n //int visibleCount = 0;\n\n while (true)\n {\n if (hasTextChanged)\n {\n totalVisibleCharacters = textInfo.characterCount; // Update visible character count.\n hasTextChanged = false;\n }\n\n if (visibleCount > totalVisibleCharacters)\n {\n yield return new WaitForSeconds(0.01f);\n //visibleCount = 0;\n }\n\n textComponent.maxVisibleCharacters = visibleCount; // How many characters should TextMeshPro display?\n\n visibleCount += 1;\n yield return new WaitForSeconds(0.1f);\n yield return null;\n }\n}\n\n// Use this for initialization\nvoid Start()\n{\n first = GetComponent<Animator>();\n //m_TextComponent = GetComponent<TMP_Text>();\n\n //TMP_Text m_TextComponent = gameObject.GetComponent(typeof(TMP_Text)) as TMP_Text;\n StartCoroutine(RevealCharacters(m_TextComponent));\n}\n\n// Update is called once per frame\nvoid Update()\n{\n\n if (Input.GetMouseButtonDown(0))\n {\n RaycastHit hit;\n Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);\n\n if (Physics.Raycast(ray, out hit))\n {\n Debug.Log(hit.collider.name);\n temp = hit.collider.name.ToString();\n\n if (temp == "Component_001")\n {\n Debug.Log("open trig");\n first.SetTrigger("open");\n }\n if (temp == "Fan_half004")\n {\n //Debug.Log(m_TextComponent.ToString());\n m_TextComponent.text = "FAN \\nThe fan is the first component in a turbofan. The large spinning " +\n "fan sucks in large quantities of air. Most blades of the fan are made of titanium. " +\n "It then speeds this air up and splits it into two parts. One part continues through the core or centre of the engine, " +\n "where it is acted upon by the other engine components.The second part bypasses the core of the engine." +\n "It goes through a duct that surrounds the core to the back of the engine where it produces much of the " +\n "force that propels the aeroplane forward.This cooler air helps to quiet the engine as well as adding thrust to the engine.";\n if (temp != tempOld)\n {\n visibleCount = 0;\n }\n tempOld = temp;\n if (firstTrig == false)\n {\n first.ResetTrigger("part1In");\n Debug.Log("part1out " + tempOld.ToString());\n first.SetTrigger("part1out");\n firstTrig = true;\n return;\n }\n if (firstTrig)\n {\n first.ResetTrigger("part1out");\n Debug.Log("part1In " + tempOld.ToString());\n first.SetTrigger("part1In");\n firstTrig = false;\n return;\n }\n\n }\n if (temp == "Cylinder074")\n {\n m_TextComponent.text = "Compressor \\nThe compressor is the first component in the engine core. " +\n "The compressor is made up of fans with many blades and attached to a shaft." +\n " The compressor squeezes the air that enters it into progressively smaller " +\n "areas, resulting in an increase in the air pressure. This results in an " +\n "increase in the energy potential of the air. The squashed air is forced into " +\n "the combustion chamber.";\n if (temp != tempOld)\n {\n visibleCount = 0;\n }\n tempOld = temp;\n if (secondTrig == false)\n {\n first.ResetTrigger("part2In");\n secondTrig = true;\n Debug.Log("part2out " + tempOld.ToString());\n first.SetTrigger("part2out");\n return;\n }\n if (secondTrig)\n {\n first.ResetTrigger("part2out");\n Debug.Log("part2In " + tempOld.ToString());\n first.SetTrigger("part2In");\n secondTrig = false;\n return;\n }\n\n }\n\n if (temp == "Circle055")\n {\n m_TextComponent.text = "Combustor \\nIn the combustor, the air is mixed with fuel and then " +\n "ignited. There are as many as 20 nozzles to spray fuel into the airstream." +\n " The mixture of air and fuel catches fire. This provides a high temperature, " +\n "high-energy airflow. The fuel burns with the oxygen in the compressed air, " +\n "producing hot expanding gases. The inside of the combustor is often made of " +\n "ceramic materials to provide a heat-resistant chamber. The heat can reach 2000\xc2\xb0C " +\n "or more.";\n if (temp != tempOld)\n {\n visibleCount = 0;\n }\n tempOld = temp;\n if (thirdTrig == false)\n {\n first.ResetTrigger("part3In");\n thirdTrig = true;\n Debug.Log("part3Out " + tempOld.ToString());\n first.SetTrigger("part3Out");\n return;\n }\n if (thirdTrig)\n {\n first.ResetTrigger("part3Out");\n Debug.Log("part3In " + tempOld.ToString());\n first.SetTrigger("part3In");\n thirdTrig = false;\n return;\n }\n\n }\n if (temp == "Object028" || temp == "Object027")\n {\n m_TextComponent.text = "Nozzle \\nThe nozzle is the exhaust duct of the engine. This is " +\n "the engine part which actually produces the thrust for the plane. The " +\n "energy depleted airflow that passed the turbine, in addition to the colder " +\n "air that bypassed the engine core, produces a force when exiting the " +\n "nozzle that acts to propel the engine, and therefore the aeroplane, " +\n "forward. The combination of the hot air and cold air are expelled and " +\n "produce an exhaust, which causes a forward thrust. The nozzle may be " +\n "preceded by a mixer, which combines the high-temperature air coming from " +\n "the engine core with the lower temperature air that was bypassed in the " +\n "fan";\n if (temp != tempOld)\n {\n visibleCount = 0;\n }\n tempOld = temp;\n if (fourthTrig == false)\n {\n visibleCount = 0;\n first.ResetTrigger("part4In");\n fourthTrig = true;\n Debug.Log("part4Out " + tempOld.ToString());\n first.SetTrigger("part4Out");\n return;\n }\n if (fourthTrig)\n {\n first.ResetTrigger("part4Out");\n Debug.Log("part4In " + tempOld.ToString());\n first.SetTrigger("part4In");\n fourthTrig = false;\n return;\n }\n\n }\n //first.SetActive(false);Fan_half004\n }\n }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n}
\n\n喷气发动机和动画控制器的图像附在下面。
\n\n\n\n\n\n请帮助我解决问题。预先感谢您。\nRanjith
\n