• 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 JackoMiG · Jul 13, 2015 at 07:43 AM · arrayanimatormecanimswapweaponchanging

Animator state not activating immediately.(URGENT)

Hi guys,

I'm trying to get weapon switching to work for my weapons that use animators.

Basically, what should happen is when the player presses 1 the first weapon in the array should be activated and the animator should go from 'any state' to 'equip' so that it looks like the weapon is being equipped. However, activating this weapon for a split second you can see that the weapon is in (if we are standing still) 'idle', before then going to play the'entry' animation.

Anyone know what's going on here?

Here's relevent parts of the script. var availableWeapons : GameObject[]; //an array of all available weapons var animator : Animator; //stores the animator component

 function Start () {
  
 animator = GameObject.Find("AUG").GetComponent(Animator);//assigns Animator component when we start the game
 //GetComponentInChildren(Animator); //assigns Animator component when we start the game
 
     var currentWeaponObject = availableWeapons[0];//NEW 06/07/2015
     //currentWeaponObject.transform.parent = weaponCam.transform; //set the weapon to be a child of the weapon camera
     currentWeapon = currentWeaponObject.GetComponent(Weapon_Base); //set the "currentWeapon" to this weapon
  
 }
 
 function Update (){
 
 if (Input.GetKeyDown("1"))
     {
         SelectWeapon(0); //selects the first weapon when '1' is pressed
         animator = GameObject.Find("AUG").GetComponent(Animator);
         animator.SetTrigger("Switch");
         var currentWeaponObject = availableWeapons[0];
         animator.SetTrigger("Switch");
         currentWeapon = currentWeaponObject.GetComponent(Weapon_Base);
         fireRate = 0.15;
         gui_ClipCount.text = ""+currentWeapon.clipAmmo; 
         gui_ReserveCount.text = ""+currentWeapon.reserveAmmo;
     } 
     if (Input.GetKeyDown("2")) 
     {
         SelectWeapon(1); //selects the second weapon when '2' is pressed
         animator = GameObject.Find("M9").GetComponent(Animator);
         animator.SetTrigger("Switch");
         currentWeaponObject = availableWeapons[1];//sets the current weapon object to the second weapon assigned in the array (through the inspector)
         currentWeapon = currentWeaponObject.GetComponent(Weapon_Base);//this is for the weapon base script which holds how many bullets we have
         fireRate = 0.5;
         gui_ClipCount.text = ""+currentWeapon.clipAmmo; 
         gui_ReserveCount.text = ""+currentWeapon.reserveAmmo;
     }
 }
 function SelectWeapon(index : int) //FUNCTION FOR SWAPING WEAPONS
 {
     for(var obj:GameObject in availableWeapons)obj.SetActive(false); //these lines just cycle through the weapons in our array
      availableWeapons[index].SetActive(true); //selects one to be active, and the rest to be inactive
 }
Comment
Add comment · Show 3
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 iamsidv · Jul 13, 2015 at 08:57 AM 0
Share

can you share the animator controller's screenshot?

avatar image Cherno · Jul 13, 2015 at 09:35 AM 0
Share

Does the transition have an exit time set?

avatar image JackoMiG · Jul 13, 2015 at 09:45 AM 0
Share

Animator controller for the AUG: alt text

dump24.jpg (102.5 kB)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

23 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

Related Questions

Non-existent gameObjects appearing. 2 Answers

Mecanim animation not working as expected. 2 Answers

[Mecanim]How to transform a part of your current state machine in a sub state machine? 1 Answer

Blending Animator Animations with Ragdoll 2 Answers

How do I control two armature animations in one gameObject? (Mecanim) 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