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 Skippy · Oct 20, 2012 at 05:45 AM · fpsgundelayreload

Reload help

So i'm not the most experienced coder, but i try. I recently started a zombie FPS, i've got all the A.I. worked out and everything, but my one issue is I can shoot while reloading. I dont know how to add delay and i was wondering if anyone could tell me how/where to put in my script. Here it is:

pragma strict

 var Range : float = 1000;
 var Force : float = 1000;
 
 var hitMark : GameObject;
 
 var texta : GUITexture;
 var four : Texture;
 var three : Texture;
 var two : Texture;
 var one : Texture;
 var zero : Texture;
 var five : Texture;
 
 var bullets : int = 5;
 
 function Start () {
 
 }
 
 function Update () {
 
 }
     
     if(Input.GetKeyDown(KeyCode.R)){
 
 
     if(bullets == 5){ texta.guiTexture.texture = five; }
     
             else if(bullets == 0){ GameObject.Find("Gun").animation.Play("reload"); bullets = 5; }
             else if(bullets == 4){ texta.guiTexture.texture = four; }
             else if(bullets == 3){ texta.guiTexture.texture = three; }
             else if(bullets == 2){ texta.guiTexture.texture = two; }
             else if(bullets == 1){ texta.guiTexture.texture = one; }
                 
         
         var hit : RaycastHit;
                 
         var direction : Vector3  = transform.TransformDirection(Vector3.forward);
          
         Debug.DrawRay(transform.position , direction * Range , Color.blue);
                 
             if(Input.GetMouseButtonDown(0)){
             
             bullets--;
                 
                 if(Physics.Raycast(transform.position , direction , hit, Range)){
                 
                             var hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
                     
                             if(hit.collider.gameObject.tag == "zombie"){
                 
                                 //hit.rigidbody.AddForceAtPosition( direction * 100 , hit.point);
                                 //hit.collider.gameObject.animation.Play("die");
                                 Instantiate(hitMark);
                                 hit.collider.gameObject.SendMessage("ApplyDamage", 45);
 
     }
 }
                                 
                             }
                 
                 
                         
 }
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 Shrandis · Dec 21, 2012 at 03:35 PM 0
Share

Helloooooooo OP, are you still there? Someone needs to tick an answer to close the question. And you said it worked... :(

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Shrandis · Oct 20, 2012 at 05:58 AM

At the line you check for user input:

 if(Input.GetMouseButtonDown(0))


check if there are bullets in the mag

 if(bullets > 0 && Input.GetMouseButtonDown(0))

However, I noticed you set the bullets to 5 the moment you start playing your reload animation. So, you either set bullets to 5 after the animation ends (you can use a coroutine or you can detect when the animation ends by using Animation Events. Check AddAnimation in script documentation for more info) or you can just check if the reload animation is playing:

 if (animation.IsPlaying("Reload") && Input.GetMouseButtonDown(0))
Comment
Add comment · Show 2 · 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 Skippy · Oct 20, 2012 at 02:02 PM 0
Share

thanks it worked

avatar image Geo.Ego · Dec 21, 2012 at 05:06 PM 0
Share

@Skippy, you should mark this as the answer if it worked for you. If you're unsure of how to do so, it's the little checkmark under the thumbs up and thumbs down symbols to the left of the answer. It will help others who may have the same problem in the future.

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

11 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

Related Questions

Multiple Cars not working 1 Answer

How do I put a delay on a gunshot? 2 Answers

Gun reload and clip size 0 Answers

Switch Weapon Script Not taking effect HELP!! 2 Answers

Get a gun off a wall 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