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 /
avatar image
0
Question by Weirdo-Studios · Jul 04, 2013 at 03:59 PM · animationraycastfpsreload

Reload FPS Animation Not Playing (Javascript)

Ok so i have my shoot script and everything works fine but when i reload it plays first couple frames then cuts. then has 3.3 reload time and adds bullets back but without the animation.

 //Gun Stats
 
 var Damage : float;
 var Range : float = 1000;
 var Force : float = 500;
 var Clips : int = 2;
 var BulletsPerClip : int = 12;
 var ReloadTime : float = 3.3;
 var BulletsLeft : int = 0;
 var ShootTimer : float = 0;
 var ShootCooler : float = 0.6;
 public var ShootAudio : AudioClip;
 public var ReloadAudio : AudioClip;
 var Aiming: boolean = false;
 var Gun : GameObject;
 
 function Start(){
 
     BulletsLeft = BulletsPerClip;
     
 
 }
 
 
 function Update () {
     
     if (ShootTimer > 0){
         ShootTimer -= Time.deltaTime;
     }
     
     if(ShootTimer < 0){
         ShootTimer = 0;
     }
     
     if(Input.GetMouseButtonDown(0) && BulletsLeft)
     {
         if(ShootTimer ==0){
             RayShoot();
             PlayShootAudio();
             ShootTimer = ShootCooler;
         }
     }
 
     if (Input.GetMouseButtonUp(1))
     {
         Aiming = false;
     }
     
         if (Input.GetMouseButtonDown(1))
     {
         Aiming = true;
     }
 }
 
 function RayShoot () {
     if(Aiming == true){
         Gun.animation.Play("ShootingAiming");
     }
     
     else if(Aiming == false){
     
         Gun.animation.Play("ShootingIdle");
     }
     var Hit : RaycastHit;
     var DirectionRay : Vector3 = transform.TransformDirection(Vector3.forward);
     
     Debug.DrawRay(transform.position, DirectionRay * Range, Color.blue);
     if(Physics.Raycast(transform.position , DirectionRay , Hit , Range)){
         
         if(Hit.rigidbody) {
             Hit.rigidbody.AddForceAtPosition(DirectionRay * Force, Hit.point);
         }
     }
 
     BulletsLeft --;
     
     if(BulletsLeft <0){
         BulletsLeft = 0;
     }
     
     if(BulletsLeft == 0){
         Reload();
     }
 }
 
 
 function Reload() {
     PlayReloadAudio();
     Gun.animation.Play("Reload", PlayMode.StopAll);
     yield WaitForSeconds(ReloadTime);
     if(Clips > 0){
     
         BulletsLeft = BulletsPerClip;
     }
 }
 
 function PlayShootAudio(){
     audio.PlayOneShot(ShootAudio);
 }
 
 function PlayReloadAudio(){
     audio.PlayOneShot(ReloadAudio);
 }
Comment
Add comment · Show 6
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 Benproductions1 · Jul 05, 2013 at 04:18 AM 0
Share

That probably has more to do with the animation then your script. Use the animation window to preview the animation you have and see if it's the same as it is when you click play :)

avatar image Weirdo-Studios · Jul 05, 2013 at 06:03 PM 0
Share

I quadra checked the anim that is all fine

avatar image KiraSensei · Jul 05, 2013 at 06:11 PM 0
Share

Can it be another animation that steps over this one ? Like a layer problem for example if you use the Add$$anonymous$$ixingTransform method ?

avatar image Ben-Stoneman ♦♦ · Jul 06, 2013 at 08:00 PM 0
Share

In line 89 it states:

Gun.animation.play("Reload", Play$$anonymous$$ode.StopAll)

Because play "Reload" is the first argument, it is executed first. Right after the animation is asked to play you stop all animations with the second argument. Perhaps you should stop all animations first and then play "Reload"

avatar image Benproductions1 Ben-Stoneman ♦♦ · Jul 07, 2013 at 01:01 AM 0
Share

The documentation on Play$$anonymous$$ode.StopAll specifically states "Stops all animations before playing". That should not be the cause of the problem

avatar image Weirdo-Studios · Jul 07, 2013 at 11:33 AM 0
Share

I just changed the layer it works cheers!

1 Reply

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

Answer by Weirdo-Studios · Jul 07, 2013 at 11:32 AM

Ok so i solved this i just changed the layer the reload played on.

Comment
Add comment · 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

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

18 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

Related Questions

Switch Weapon Script Not taking effect HELP!! 2 Answers

script for animation play 1 Answer

Reload Animation 0 Answers

Reload animation.... magazine hiding 0 Answers

Rayshoot Reload Problem (Can still shoot) 2 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