Hello!
I have been working on a 2d space shooter, but recently, I found an error
Whenever I play the game, I dont need to press the b key, lasers fire regardless.
Here is my code
using UnityEngine;
using System.Collections;

public class Firing : MonoBehaviour {
    public GameObject laser;
    public GameObject bulletpositiona;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update ()
    {

        if (Input.GetKey("b")) ;
        {
            GameObject bullet = (GameObject)Instantiate(laser);
            bullet.transform.position = bulletpositiona.transform.position;
        }
    }
	
}

Thank you!!

Hi you have semicolon after your If. SO what it does is If (Input.GetKey(“b”)) then do empty command. Do rest regardless of if. Just remove it and it will work fine.

 public class Firing : MonoBehaviour {
     public GameObject laser;
     public GameObject bulletpositiona;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update ()
     {
 
         if (Input.GetKey("b"))  //; Wrong semicolon
         {
             GameObject bullet = (GameObject)Instantiate(laser);
             bullet.transform.position = bulletpositiona.transform.position;
         }
     }
     
 }