Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by zukinet · Jun 07, 2017 at 08:22 AM · animationanimatoranimator controllerdelay

How to Remove Delay in Button Click to Animation

I am a noob to Unity, i am making a simple game that need fast response. so in GUI, there will be some button. if i press button X then do Animation X, then if i press button Y then do Animation Y. Currently, i just create one button to test.

But There's a problem. Whenever i click button X, there's a delay around 1-2 seconds until animation play.

Animator Scheme: alt text

Button onClick Target: alt text

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;
     }
 }
 

Maybe there's something wrong in my code, 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
 

btw, Thanks in advance...and sorry for my english...

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

202 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Animator Check the end of an animation 1 Answer

I can't see or access a state in the Animation Controler 1 Answer

Animation from child object overrided by its parent and won't show in game window 0 Answers

Applying permanent mask to player animators walk 0 Answers

Delay Animator Action in C#? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges