Bullet Firing Every Frame
So I wrote this shooting code so when the player pressed left mouse button a bullet will fire. However, a bullets if being fired every frame even when i didn't press fire. Help!!
Shooting Code:
using UnityEngine; using System.Collections;
public class PlayerShooting : MonoBehaviour {
 GameObject prefab;
   
 // Use this for initialization
 void Start()
 {
     prefab = Resources.Load("Bullet") as GameObject;
     
 }
 void FixedUpdate()
 {
     if (Input.GetMouseButtonDown(0)) ;
     {
         GameObject Bullet = Instantiate(prefab) as GameObject;
         Bullet.transform.position = transform.position + Camera.main.transform.forward * 5;
         Rigidbody rb = Bullet.GetComponent<Rigidbody>();
         rb.velocity = Camera.main.transform.forward * 100;
     }
 }
  
 
               }
    `
 
              Answer by 3tai · Sep 09, 2016 at 09:10 PM
 if (Input.GetMouseButtonDown(0)) ;
 
               you have a semicolon at the end of your if, effectively ending the if-check.
also, why are you using input within FixedUpdate() instead of Update()?
Answer by awsome129 · Sep 10, 2016 at 12:41 AM
ty for the answer that actually fixes alot of problems i have always had with unity lol. I used FixedUpdate has a desperate attempt to fix this, I just never changed it back. Ty
Your answer
 
             Follow this Question
Related Questions
Storing instantaneous velocity 0 Answers
GetKeyUp does not get called sometimes. 1 Answer
2D Sprite Frame Skipping after upgrade to 5.6.1f1 0 Answers
Unity skipping input 0 Answers