2017-06-08 5 views
0

私は簡単なゲームを作成しています速い応答が必要です。 GUIではいくつかのボタンがあります。 ボタンXを押してからアニメーションXを実行すると、ボタンYを押してアニメーションYを実行すると、現在、テストするボタンが1つだけ作成されます。Unity3D - ボタンの遅延を取り除く方法クリックしてアニメーションにする

しかし、問題があります。 ボタン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 

任意のアイデア?

ありがとうございます。

+0

アニメーションが遅れて始まることはありますか?インスペクタでアニメーションを再生するだけですぐに起動しますか? – Hristo

+0

'Any State'からあなたのアニメーションへの移行をもう一度チェックしてみませんか? –

答えて

2

これはコードのためではありません。これは、修正する必要のある遷移です(Animatorウィンドウのアニメーション状態間の白い矢印)。 TalkingStatusでトリガーする必要があるものを選択し、インスペクタでHas Exit Timeのチェックを外します。 Has Exit Timeは、トランジションの前にアニメーションが終了するのを待っています。

+0

ありがとう...これは仕事です! – anunixercoder

関連する問題