Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 yvyv1000 · Aug 25, 2016 at 08:30 PM · scripting probleminputshootinggunreload

1 script doesn't react to input

so I have a shooting script which did work at first and then I went off for a while and came back to unity to start working on the project again and suddenly only this script doesn't react to my mouse input anymore

gun won't shoot and I can reload and all that kind of stuff that's in the script does anyone know what's wrong also there are no error messages at all

here is the script

 var Damage = 10;
 var FireRate = 0.1F;
 var NextFire = 0.0F;
 var BulletRange = 200;
 var ClipAk = 30;
 var TotalBulletsAk = 90;
 var ClipUMP = 45;
 var TotalBulletsUMP = 135;
 var ReloadTime = 1;
 var Nifes = 3;
 var SpreadFactor : float = 0;
 var AimSpread : float = 0.01;
 var HipFireSpread : float = 0.01;
 var AimCamera : GameObject; 
 var BulletHole : GameObject;
 var Nife : GameObject;
 var NifeSpawn : GameObject;
 var IsReloading = false;
 var GunFireSound : AudioClip;
 var EmptyGunSound : AudioClip;
 var Gun : GameObject;
 var GunReloadSound : AudioClip;
 var AnimationPlayed = false;
 var MuzzleFlash : GameObject;
 var GunTwo : GameObject;
 var ActiveGun = 2;
 var GotGunTwo = false;
 
 function Start() {
 
     GunReloadAnimation = Gun.GetComponent.<Animator>();
 }
 
 function Update() {
 
     MuzzleFlash = gameObject.FindWithTag("MuzzleFlash");
     MuzzleFlash.GetComponent.<Renderer>().enabled = false;
     AimCamera.GetComponent.<Crosshair>().enabled = true;
     SpreadFactor = HipFireSpread;
 
     if(Input.GetButton("Fire2")){
         AimCamera.GetComponent.<Crosshair>().enabled = false;
         SpreadFactor = AimSpread;
 
     }
 }
 
 if(ActiveGun == 1){
     if(Input.GetButton("Fire1") && Time.time > NextFire && ClipAk > 0){
 
         NextFire = Time.time + FireRate;
         GetComponent.<AudioSource>().clip = GunFireSound;
         GetComponent.<AudioSource>().time = 0.2f;
         GetComponent.<AudioSource>().Play();
         Rayshooting();
         ClipAk --;
 
     }
     else if(ClipAk == 0 && TotalBulletsAk != 0){
         GetComponent.<AudioSource>().time = 0.4f;
         GetComponent.<AudioSource>().clip = GunReloadSound;
         GetComponent.<AudioSource>().Play();
         ReloadAk();
 
     }
     else if(Input.GetButtonDown("Fire1") && ClipAk == 0 && TotalBulletsAk == 0){
         EmptySound();
 
     }
 
     if(Input.GetKey(KeyCode.R) && ClipAk < 30 && TotalBulletsAk != 0 && IsReloading == false) {
         GetComponent.<AudioSource>().time = 0.4f;
         GetComponent.<AudioSource>().clip = GunReloadSound;
         GetComponent.<AudioSource>().Play();
         ReloadAk();
 
     }
 }
 
 if(ActiveGun == 2){
     if(Input.GetButton("Fire1") && Time.time > NextFire && ClipUMP > 0){
 
         NextFire = Time.time + FireRate;
         GetComponent.<AudioSource>().clip = GunFireSound;
         GetComponent.<AudioSource>().time = 0.2f;
         GetComponent.<AudioSource>().Play();
         Rayshooting();
         ClipUMP --;
 
     }
     else if(ClipUMP == 0 && TotalBulletsUMP != 0){
         GetComponent.<AudioSource>().time = 0.4f;
         GetComponent.<AudioSource>().clip = GunReloadSound;
         GetComponent.<AudioSource>().Play();
         ReloadUMP();
 
     }
     else if(Input.GetButtonDown("Fire1") && ClipUMP == 0 && TotalBulletsUMP == 0){
         EmptySound();
 
     }
 
     if(Input.GetKey(KeyCode.R) && ClipUMP < 45 && TotalBulletsUMP != 0 && IsReloading == false) {
         GetComponent.<AudioSource>().time = 0.4f;
         GetComponent.<AudioSource>().clip = GunReloadSound;
         GetComponent.<AudioSource>().Play();
         ReloadUMP();
 
     }
 }
 
     if(Input.GetKeyDown(KeyCode.E) && Nifes > 0){
         Instantiate(Nife, NifeSpawn.transform.position, NifeSpawn.transform.rotation);
         Nifes --;
     }
 
 
 if(GotGunTwo == true){
     if(Input.GetKeyDown(KeyCode.Alpha1)){
         WeaponSwitch();
     }
 }
 
 function Rayshooting() {
     {
         MuzzleFlash.GetComponent.<Renderer>().enabled = true;
         yield WaitForSeconds(0.02);
         MuzzleFlash.GetComponent.<Renderer>().enabled = false;
     }
     var direction : Vector3 = transform.forward;
 
     direction.x += Random.Range(-SpreadFactor, SpreadFactor);
     direction.y += Random.Range(-SpreadFactor, SpreadFactor);
     direction.z += Random.Range(-SpreadFactor, SpreadFactor);
 
     Debug.DrawRay(transform.position,direction * BulletRange);
     var hit : RaycastHit;
 
         bHit = Physics.Raycast(transform.position,direction,hit,BulletRange);
         if (bHit && hit.transform.gameObject.tag == "Enemy"){
             hit.transform.SendMessage("DamageTaken", Damage, SendMessageOptions.DontRequireReceiver);
         }
         else if (bHit && hit.transform.gameObject.tag == "Buildings" || "Buildings2"){
             var CloneHole = Instantiate(BulletHole, hit.point, Quaternion.LookRotation(hit.normal));
             Destroy(CloneHole, 5);
         }
 
 } 
 
 function ReloadAk() {
 
     if(ActiveGun == 1){
         Gun.GetComponent.<Animation>().Play("Reload");
     }
     else if(ActiveGun == 2){
         GunTwo.GetComponent.<Animation>().Play("Reload UMP");
     }
     yield WaitForSeconds(ReloadTime);
 
     if(ClipAk < 30 && TotalBulletsAk > 0){
         var refill = Mathf.Min(30 - ClipAk, TotalBulletsAk);
         TotalBulletsAk -= refill;
         ClipAk += refill;
     }
 }
 
 function ReloadUMP() {
 
     if(ActiveGun == 1){
         Gun.GetComponent.<Animation>().Play("Reload");
     }
     else if(ActiveGun == 2){
         GunTwo.GetComponent.<Animation>().Play("Reload UMP");
     }
     yield WaitForSeconds(ReloadTime);
 
     if(ClipUMP < 45 && TotalBulletsUMP > 0){
         var refill = Mathf.Min(45 - ClipUMP, TotalBulletsUMP);
         TotalBulletsUMP -= refill;
         ClipUMP += refill;
     }
 }
 
 function EmptySound(){
         GetComponent.<AudioSource>().time = 0.0f;
         GetComponent.<AudioSource>().volume = 1;
         GetComponent.<AudioSource>().clip = EmptyGunSound;
         GetComponent.<AudioSource>().Play();
 }
 
 function WeaponSwitch(){
         if(Gun.active == true){
             Gun.GetComponent.<Animation>().Play("WeaponOut");
             yield WaitForSeconds(0.5);
             Gun.SetActive(false);
             GunTwo.SetActive(true);
             GunTwo.GetComponent.<Animation>().Play("WeaponIn");
             ActiveGun = 2;
         }
         else{
             GunTwo.GetComponent.<Animation>().Play("WeaponOut");
             yield WaitForSeconds(0.5);
             GunTwo.SetActive(false);
             Gun.SetActive(true);
             Gun.GetComponent.<Animation>().Play("WeaponIn");
             ActiveGun = 1;
         }
 }
Comment
Add comment
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

1 Reply

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

Answer by Landern · Aug 25, 2016 at 08:32 PM

Line 46, you close the Update function with a closing curly brace. This kills your input if statements. You should remove the closing curly brace on that line and check all of your code blocks.

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 yvyv1000 · Aug 28, 2016 at 07:19 PM 0
Share

thanks it worked for me

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

reload script does not work when ammo is 16 2 Answers

Help with reloading gun. 1 Answer

How can I shoot bullets that you can aim with the crosshair? 1 Answer

GetButtonDown problem | C# 0 Answers

Control amount of bullets 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