• 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
-1
Question by logang · Mar 31, 2013 at 03:30 AM · javareloadrecoil

Gun recoil and gun reload

Okay I have been working on my first game and I was going to publish the demo. But I cant find out how to make a gun recoil and gun reload. I have the Aiming and every thing done its just what i want to do is when you reload. It takes like 2 seconds before you get your clip full. like "yield WaitForSeconds" i cant use that because I put it in function Upate.... and I am using java.. thanks

                                              -Logan
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 robertbu · Mar 31, 2013 at 03:39 AM 0
Share

It is difficult to help you without seeing your script One simple way around the Update() issue and waiting for a reload is to have a boolean value 'isReloading' used as a flag, and the have it set and cleared in a coroutine. In Upadate() you only allow the gun to fire if the isReloading flag is false,

avatar image deltamish · Apr 02, 2013 at 03:58 PM 0
Share

do you have reload animation for your weapon and (for recoil )is your weapon is semi automatic or full auto(ie pistol or assualt rifle)

avatar image logang · Apr 02, 2013 at 04:28 PM 0
Share

it is a full auto and I dont want to post my script because its over 900 lines

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by DarkScythe97 · Mar 31, 2013 at 04:57 AM

Well here's one way you could do the reloading:

 public var reloading : boolean; //Are we reloading?
 public var reloadTime : float; //Time it takes to reload.
 
 private var reloadTimer : float; //Var that keeps track of time.
 
 function Update()
 {
     //If we press reload and we aren't already reloading...
     if (!reloading && Input.GetButtonDown("ReloadButton"))
     {
         reloading = true; //Start reloading.
         reloadTimer = Time.time + reloadTime; //Set time to stop reloading.
     }
     
     //If we're reloading and the current time is more than the stop time...
     if (reloading && Time.time > reloadTimer)
     {
         reloading = false; //Stop reloading.
     }
 }
Comment
Add comment · Show 1 · 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 logang · Mar 31, 2013 at 01:26 PM 0
Share

Okay thanks

avatar image
0

Answer by deltamish · Apr 02, 2013 at 04:36 PM

Hi here is the script

 var reload:boolean = false;
 var weapon:Transform;
 var ReloadAnim:AnimationClip;
 var maxrot:float = 5;///rotate your weapon and copy y axis rotation
 function Update(){
 if(reload){
 weapon.animation.CrossFade(ReloadAnim.name);
 if(!weapon.animation.IsPlaying(ReloadAnim.name)){
 ///amooinclp = ammoperclip;
 reload = false;
 }
 weapon.localRotation.y = Mathf.Lerp(weapon.localRotation.y,0,Time.deltaTime * 2);
 if(Input.GetButton("Fire1")){
 weapon.localRotation.y = Mathf.Lerp(weapon.localRotation.y,maxrot,Time.deltaTime * 2);
 }
 }
 }
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.

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

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

How do I Reset Scene 1 Answer

script for animation play 1 Answer

Error Java script 1 Answer

Camera Recoil,Please help me. 2 Answers

how can i add a gun sound to this script? 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