Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by george3d2011 · Nov 23, 2013 at 10:26 AM · animationreloadingoncewrapmode

How to make Reloading animation play ONCE

hey guys I am making an FPS game and i reached the level where i make the reloading animations So, I have a boolean and whenever this boolean comes true my reloading animation and sound takes place. Unfortunately I have made a mistake on my scripting so that boolean never goes false as a result my animation never stops playing and i can't continue playing. I have tried to set the wrapMode to ONCE but nothing happends it continues playing like loop. I also tried to make the wrapMode.Once through scripting but also NOTHING happends my animation never stops playing. I have posted my script, let me know if I have skipped any information you may need to troubleshoot my problem.

Here is my script:

 public int currentClip = 6;
 public int currentExtraAmmo = 12;
 public int maxExtraAmmo = 24;
 public int clipSize = 6;
 public bool reloading;
 
 //Animations
     public void AnimationController()
     {
         //JUMP ANIMATIONS
         if(wasStanding && !CharCont.isGrounded)
         {
             wasStanding = false;
             WalkAnimationHolder.animation.Play("Jump");
         }
         else if (!wasStanding && CharCont.isGrounded)
         {
             wasStanding = true;
             WalkAnimationHolder.animation.Play("JumpLanding");
         }
         //RUNNING ANIMATIONS
         if(walkingstate == WalkingState.Running)
         {
             WalkAnimationHolder.animation["Run"].speed = VelocityMagnitude / RunSpeed * 1.2f;
             WalkAnimationHolder.animation.CrossFade("Run", 0.2f);
         }
         //WALKING ANIMATION
         else if (walkingstate == WalkingState.Walking && !reloading)
         {
             WalkAnimationHolder.animation["Walk"].speed = VelocityMagnitude / WalkSpeed * 1.2f;
             WalkAnimationHolder.animation.CrossFade("Walk", 0.2f);
         }
         //RELOADING ANIMATION WHILE WALKING
     else if (walkingstate == WalkingState.Walking && reloading == true)
         {
         WalkAnimationHolder.animation["Reload"].wrapMode = WrapMode.Once;
             WalkAnimationHolder.animation.CrossFade("Reload");
         }
         //RELOADING ANIMATION WHILE STAYING PUT
         else if (walkingstate == WalkingState.Idle && reloading == true)
         {
             WalkAnimationHolder.animation["Reload"].wrapMode = WrapMode.Once;
             WalkAnimationHolder.animation.CrossFade("Reload");
         }
         //IDLE ANIMATION
         else
         {
             WalkAnimationHolder.animation.CrossFade("Idle", 0.2f);
         }
     }
 
 //Shoot Station
     public void ShootController()
     {
                 //RELODING LOGIC
         if(currentClip > clipSize)
             currentClip = clipSize;
         if(currentExtraAmmo > maxExtraAmmo)
             currentExtraAmmo = maxExtraAmmo;
         if(currentClip < 0)
             currentClip = 0;
         if(currentExtraAmmo < 0)
             currentExtraAmmo = 0;
         //RELOADING BUTTONS AND ACTIONS
         if(!reloading && Input.GetButtonDown("Reload") && currentClip < clipSize && currentExtraAmmo > 0)
         {
             reloading = true;
         }
         //RELOADING BUTTONS AND ACTIONS
         if(!reloading && Input.GetButtonDown("Fire1") && currentClip == 0 && currentExtraAmmo > 0)
         {
             reloading = true;
         }
             //STOPING THE ANIMATION AND RETURN false
             if(reloading && !WalkAnimationHolder.animation.IsPlaying("Reload"))
     {
         if(currentExtraAmmo >= clipSize - currentClip)
         {
             currentExtraAmmo -= clipSize - currentClip;
             currentClip = clipSize;
         }
         
         if(currentExtraAmmo < clipSize - currentClip)
         {
             currentClip += currentExtraAmmo;
             currentExtraAmmo = 0;
         }
         reloading = false;
     }
         //BASIC SHOOTING SYSTEM + RECOIL + SOUND
         if (Input.GetButtonDown("Fire1") && currentClip > 0 && !reloading)
         {
             if (shoottime <= Time.time)
             {
                 shoottime = Time.time + CurrentWeapon.firerate;
                 CurrentRecoil1 += new Vector3(CurrentWeapon.RecoilRotation.x, Random.Range(-CurrentWeapon.RecoilRotation.y, CurrentWeapon.RecoilRotation.y));
                 CurrentRecoil3 += new Vector3(Random.Range(-CurrentWeapon.RecoilKickback.x, CurrentWeapon.RecoilKickback.x), Random.Range(-CurrentWeapon.RecoilKickback.y, CurrentWeapon.RecoilKickback.y), CurrentWeapon.RecoilKickback.z);
             }
  
             GameObject inst_bullet = Instantiate(CurrentWeapon.Bullet, CurrentWeapon.Spawnpoint.position, CurrentWeapon.Spawnpoint.rotation) as GameObject;
             inst_bullet.rigidbody.AddRelativeForce(Vector3.forward, ForceMode.Impulse);
             Physics.IgnoreCollision(inst_bullet.collider, CharCont);
             currentClip -= 1;
             if (bulletSound)
             {
                 holdSound = Instantiate(bulletSound, CurrentWeapon.Spawnpoint.transform.position, CurrentWeapon.Spawnpoint.transform.rotation) as GameObject;
             }
             if (holdSound)
             {
                 holdSound.transform.parent = transform;
             }
         }
     }

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

16 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

Related Questions

Death animation play more than once 1 Answer

AI function/coroutine animation issues 2 Answers

Wrap Mode in animator not working properly 0 Answers

Once Animation Wrapmode v4.3.3 0 Answers

Animation Wrap Mode Usage? 1 Answer


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