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 Mackan66 · Jul 06, 2013 at 08:00 PM · ammoweaponsgunsautomated

My automatic gun don't work help!

My shoot script don't work at least not the automatic gun all my ammo disapers at ones please help me i really need this

My script:

pragma strict

var Effect : Transform; var TheDammage = 100; var shootSound : AudioClip; var ammo : int; var NoAmmoSound : AudioClip; var MaxAmmo : int = 13; var BulletHole : Transform; var FullAuto : boolean = false; var FireRate : float = 0.01; private var NextFire : float = 0.0;

function start () {

}

function Update () {

 if (Input.GetKeyDown("x"))
 {
     if (FullAuto == true)
     {
     FullAuto = false;
     }
     else
     {
     FullAuto = true;
     }
 }
 
 if (FullAuto == true)
  {
     if (Input.GetMouseButton(0)&& Time.time > NextFire)
     {
         NextFire = Time.time + FireRate;
         AMMO();
         Fire();
     }
 }
 
     if (FullAuto == false)
  {
 
 if (Input.GetMouseButtonDown(0))
 {
     AMMO();
     Fire();
 }
 }

     
     if(ammo > MaxAmmo)
        ammo = MaxAmmo;
     

}

function OnGUI() { //Shows how mush ammo you have. if(ammo > 0) { GUI.Label(Rect(20,15,25,25),ammo.ToString()); } if(ammo == 0) { GUI.Label(Rect(20,15,45,45),"No Ammo"); } }

function Fire() {

 var hit : RaycastHit;
 var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
                 
         
     if (Physics.Raycast (ray, hit, 100))
     {
         if(ammo > 0)
         {
         var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
         Destroy(particleClone.gameObject, 5);
         hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
         }
     }
 
 FireSound();
 
 if(ammo > 0)
 {        
     if(hit.collider.tag == "Prop")
     {
         Instantiate(BulletHole,hit.point,Quaternion.FromToRotation(Vector3.forward,hit.normal));
     }
 }

} function FireSound() {
if(ammo < 1) { if (Input.GetMouseButtonDown(0)) audio.PlayOneShot(NoAmmoSound); }

     if(ammo > 0)
     {
     if (Input.GetMouseButtonDown(0))
     audio.PlayOneShot(shootSound);
     }

}

function AMMO() { if (ammo > 0) { ammo --; } }

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 Vox Nephila · Jul 06, 2013 at 08:43 PM 2
Share

You should really revise your post. Grammar errors need to be fixed in the opening, and the code needs to be formatted better. I immediately lost interest and will thus, not be attempting to answer this, but rather tell you this so you can improve the post.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Mackan66 · Jul 27, 2013 at 12:48 PM

I have fixed the problem now.

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

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

pick up ammo from specific gun? 1 Answer

VR Weapons. New to Unity and need help. 2 Answers

my son is doing a multiplayer fps and is having a problem when each player picks up a gun and when one player shoots the other players gun fires to 4 Answers

Stop checking for key input 1 Answer

reset delay bar and and ammo 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