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 /
avatar image
0
Question by ElementalVenom · Sep 28, 2015 at 06:40 AM · unity 5animator

Animation in animator not always working(only sometimes)

Hey guys me again. So ive just recently started using animators instead of just the animation because im making more and more games that are multiplayer. So the problem im having is this: I have a script that is suppose to play a shooting animation when i click and deduct 1 ammo point. Its deducting the ammo but only plays the animation every 4-6 shots. Can you help me? Code: using UnityEngine; using System.Collections;

 public class Shooting : MonoBehaviour {
     int ammo;
     int maxAmmo;
     int weapon=1;
     int pocketAmmo;
     int maxPocketAmmo=32;
     GameObject eyes;
     bool canShoot=true;
     // Use this for initialization
     void Start () {
         if(weapon==1){
             pocketAmmo=maxPocketAmmo;
             maxAmmo=8;
             ammo=maxAmmo;
         }
         GameObject Head=GetComponent<PlayerController>().Head;
         eyes=Head.transform.FindChild("Eyes").gameObject;
     }
     public void buyAmmo(){
         if(GetComponent<Shop>().getMoney()>=50){
             addAmmo(32);
             ammo=maxAmmo;
             GetComponent<Shop>().removeMoney(50);
         }
     }
     public void addAmmo(int ammount){
         pocketAmmo=maxPocketAmmo;
     }
     // Update is called once per frame
     void Update () {
         if(Input.GetMouseButtonDown(0) && ammo>0 && canShoot){
             ammo-=1;
             //if(GetComponent<Animator>().GetCurrentAnimatorStateInfo(1).IsName("Glock-Shoot")){
                 Debug.Log("Fired");
                 transform.GetComponent<Animator>().SetBool("isShootingGlock",true);
             //}
 
             shoot(1);
             StartCoroutine("shootTimer",0.317f);
         }
         if(Input.GetKeyDown(KeyCode.R) && ammo<8 && pocketAmmo>0){
             int tmpInt=0;
             if(pocketAmmo>=maxAmmo){
                 tmpInt=maxAmmo-ammo;
                 pocketAmmo-=tmpInt;
                 ammo=maxAmmo;
             }else{
                 tmpInt=0;
                 tmpInt=maxAmmo-ammo;
                 if(pocketAmmo>=tmpInt){
                     pocketAmmo-=tmpInt;
                 }else{
                     ammo+=pocketAmmo;
                     pocketAmmo=0;
                 }
             }
         }
     }
     IEnumerator shootTimer(float waitTime){
         yield return new WaitForSeconds(waitTime);
         transform.GetComponent<Animator>().SetBool("isShootingGlock",false);
         canShoot=true;
     }
     void shoot(int Damage){
         canShoot=false;
 
         RaycastHit hit;
         Physics.Raycast(transform.position,eyes.transform.forward, out hit,99);
         if(hit.transform.tag=="Zombie" && hit.transform.GetComponent<Health>()!=null && hit.transform.GetComponent<Health>().dieID==2){
             hit.transform.GetComponent<PhotonView>().RPC("takeDamage",PhotonTargets.AllBuffered,2);
 
         }
 
     }
 
     void OnGUI(){
         GUI.Box(new Rect(Screen.width-Screen.width/6,Screen.height-Screen.height/6,Screen.width/7,Screen.height/7),""); 
         GUI.skin.label.fontSize=Screen.height/12;
         GUI.Label(new Rect(Screen.width-Screen.width/7,Screen.height-Screen.height/9.3f,Screen.width/5,Screen.height/5),ammo.ToString());
 
         if(pocketAmmo>9){
             GUI.skin.label.fontSize=Screen.height/7;
             GUI.Label(new Rect(Screen.width-Screen.width/8,Screen.height-Screen.height/6,Screen.width/5,Screen.height/5),pocketAmmo.ToString());
         }
         else{
             GUI.skin.label.fontSize=Screen.height/7;
             GUI.Label(new Rect(Screen.width-Screen.width/9,Screen.height-Screen.height/6,Screen.width/5,Screen.height/5),"0"+pocketAmmo.ToString());
         }
     }
 }
 
Comment
Add comment · Show 1
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
avatar image ElementalVenom · Sep 27, 2015 at 02:45 PM 0
Share

BTW the animation is 0.317 seconds long.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ElementalVenom · Oct 07, 2015 at 09:42 PM

Fixed by setting the animation to not have a transition time. As in it instantly changes animation state.

Comment
Add comment · Show 1 · Share
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
avatar image kaliAJ · Jan 31, 2020 at 11:38 AM 0
Share

@ElementalVenom where is that transition time settings located?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to run my jump animation in unity3d? 0 Answers

"StateMachineBehaviour" Not working for sub sates ? 0 Answers

Animation State Machine Script Control Issue 1 Answer

Unity 5 - Animator and Mesh Renderer 0 Answers

How do I scale an Imported Animated Object?, 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