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 lazlo · Dec 30, 2012 at 04:57 PM · gunsprojectiles

Beginner gun script, 4.0 woe, assistance sought

The problem is not the script,the script works fine the problem is that in unity 4.0 the function
animation.Play("walking")
isnt working i dont know what to do for that so if someone knows plz help me because have stuck at this problem for almost 3 months and i can do nothing!!

here is the script if anyone knows hot to make the animation to play in unity 4.0 plz help me

 var Clips : int = 20; 
 var Range : float = 900; 
 var Force : float = 900; 
 var BulletsInClip : int = 27; 
 var RelodeTime : float = 4; 
 var BulletsLeft : int = 0; 
 var ShootTimer : float = 0; 
 var ShootCooler : float =0.9; 
 var RelodingAudio : AudioClip; 
 var ShootingAudio : AudioClip;
 var ShootingAnimation : Animation;
 var ReloadingAnimation : Animation;
 var ReloadingString : String;
 var ShootingString : String;
 
 
 function Start () 
 { 
     BulletsLeft = BulletsInClip; 
 } 
 
 function Update () 
 { 
     if (ShootTimer > 0) 
     {
         ShootTimer -= Time.deltaTime; 
     } 
 
     if (ShootTimer < 0) 
     {
         ShootTimer = 0; 
     } 
 
     if (Input.GetMouseButton(0)&& BulletsLeft > 0) 
     {
         if(BulletsLeft == 0) 
         {
             Relode(); 
         } 
 
         if (ShootTimer == 0) 
         {
             Shooter(); 
             ShootTimer = ShootCooler; 
         }
     }
 
     if (Input.GetKeyDown(KeyCode.R))
     { 
         Relode(); 
     }  
 }
 
 
 
 function Shooter () 
 {
     ShootingAnimation.Play(ShootingString);
     var Hit : RaycastHit; 
     var DirectionRay = transform.TransformDirection(Vector3.forward); 
     if(Physics.Raycast(transform.position, DirectionRay,Hit,Range)) 
     { 
 
         if (Hit.rigidbody) 
         { 
             Hit.rigidbody.AddForceAtPosition(DirectionRay* Force, Hit.point); 
         } 
     } 
     BulletsLeft --; 
     PlayShootAudio(); 
     if(BulletsLeft < 0) 
     { 
         BullletsLeft =0; 
     } 

     if(BulletsLeft == 0) 
     { 
         Relode(); 
     } 
 } 
 
 function Relode () 
 { 
     PlayRelodeAudio(); 
     ReloadingAnimation.Play(ReloadingString);
     yield WaitForSeconds(RelodeTime); 

     if(Clips > 0) 
     {
         BulletsLeft = BulletsInClip; Clips --; 
     } 
 } 
 
 function PlayShootAudio () 
 {
     audio.PlayOneShot(ShootingAudio); 
 }
 
 function PlayRelodeAudio () 
 {
     audio.PlayOneShot(RelodingAudio); 
 }
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 Lovrenc · Dec 30, 2012 at 04:59 PM 1
Share

Edit your question title. Edit the code, this is unreadable. And add builder error message.

avatar image Piflik · Dec 30, 2012 at 05:02 PM 1
Share

Please format your code correctly on future posts. Fixed it for you this time.

avatar image AlucardJay · Jan 07, 2013 at 09:00 AM 0
Share

You have already accepted an answer, so unless Piflik can help, am not sure you'll get new people reading this. If you cannot undo the accepted answer, you may have to ask a new question for more traffic. $$anonymous$$ake sure you link back to this question (to avoid duplicate question confusion. I don't know, but this may be the best way for you to get an answer =]

Edit : I cannot see anywhere in your code the line animation.Play("walking")

1 Reply

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

Answer by Piflik · Dec 30, 2012 at 05:34 PM

Without knowing what exactly does not work, there is only a limited amount of insight I can give you.

First, (BulletsLeft == 0) is never true inside if(BulletsLeft > 0). Even if you pull it below the shoot part, where BulletsLeft is decremented it is still redundant, since you reload as part of the shooter function.

if(BulletsLeft < 0) inside the shooter function is redundant, since it is only called when you have at least one bullet left.

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

12 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

Related Questions

bullet physics using raycast? 3 Answers

Adding a gun and creating an animation for a 2d character to move with a animation. 1 Answer

Projectiles too fast for Physics 3 Answers

C# - stop instantiated objects from inheriting the last 1 Answer

Space Skybox implementation 5 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