Unity3D - 如何删除按钮中的延迟单击动画

时间:2017-06-08 03:59:13

标签: c# animation unity3d unity5 unityscript

我正在制作一款需要快速响应的简单游戏。所以在GUI中,会有一些按钮。 如果我按下按钮X然后按动画X ,那么如果我按下按钮Y然后按动画Y.目前,我只创建一个按钮进行测试。

但是有一个问题。 每当我点击按钮X时,会有1-2秒左右的延迟直到动画播放。

动画师方案: enter image description here

按钮onClick目标:

enter image description here

TalkingButtonScript.cs:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;

 public class TalkingButtonScript : MonoBehaviour {

     public Button Text;
     public AudioClip sound;
     public Animator ani;
     public Canvas yourcanvas;
     Animator myAnimator;
     public PlayerAnimatorControllerScript cas;

     void Start () 
     {
         Text = Text.GetComponent<Button> ();
         ani.enabled = true;
         yourcanvas.enabled = true;
     }

     public void Press() 
     {
         PlayerAnimatorControllerScript.instance.talking_btn_clicked = true;
     }
 }

PlayerAnimatorControllerScript.cs:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;

 public class PlayerAnimatorControllerScript : MonoBehaviour {

     public static PlayerAnimatorControllerScript instance;
     public float speed = 10.0f;
     public float jumpSpeed = 8.0f;
     public float gravity = 20.0f;
     private float total =0.0f;
     private Vector3 moveDirection = Vector3.zero;
     CharacterController controller;
     public Animator myAnimator;
     float currSpeed, Param1;
     bool Param2, Param3;
     public bool talking_btn_clicked = false;

     // Use this for initialization
     void Start () {
         instance = this;
         controller = GetComponent<CharacterController> ();
         myAnimator = GetComponent<Animator> ();
         //myAnimator.SetBool ("TalkingStatus", true);
     }

     public void talkingActive()
     {
         Debug.Log ("set talking button = active");
         talking_btn_clicked = true;
     }

     // Update is called once per frame
     void Update ()
     {
         Param1 = 0;
         Param2 = false;
         Param3 = false;
         if (controller.isGrounded) {

             if (talking_btn_clicked == true) {
                 myAnimator.SetBool ("TalkingStatus", true);
             }

             currSpeed = speed;
             if (Input.GetKey (KeyCode.LeftShift)) {
                 Debug.Log ("ShiftLeft Pressed");
                 Param2 = true;
                 currSpeed = speed / 2;
             }

             if (Input.GetKey (KeyCode.LeftControl)) {
                 Param3 = true;
             }


             Param1 = Mathf.Abs (Input.GetAxis ("Vertical"));
             transform.Rotate (0, Input.GetAxis ("Horizontal"), 0);
             myAnimator.SetFloat ("Speed", Param1);
             myAnimator.SetBool ("Shift", Param2);
             myAnimator.SetBool ("Attack", Param3);
             moveDirection = new Vector3 (0, 0, Input.GetAxis ("Vertical"));
             moveDirection = transform.TransformDirection (moveDirection);
             moveDirection *= currSpeed;

             if (Input.GetButton ("Jump")) {
                 moveDirection.y = jumpSpeed;
                 Param1 = 0.2f;
             }


         }//==controller.isGrounded        
         if (!myAnimator.IsInTransition(0)) {
             //Debug.Log("Animation is in Transition");
             total = gravity * Time.deltaTime;
             moveDirection.y -= gravity * Time.deltaTime;
             controller.Move (moveDirection * Time.deltaTime);
             //Debug.Log("total = "+total);
         }
     }//==update
 }//==class

任何想法?

提前致谢

1 个答案:

答案 0 :(得分:2)

这不是因为你的代码。它是您需要修复的过渡(Animator窗口中动画状态之间的白色箭头)。选择您需要使用TalkingStatus触发的那个,在检查器中取消选中Has Exit TimeHas Exit Time正在等待您的动画在转换前完成。