if statement misses a condition

It doesnt spawn anything

public class spawnbomb : MonoBehaviour {
 
    public GameObject bomb;
    public GameObject player;
    public int bomb_nr = 3;


    void Update()
    {
        if (Input.GetKeyDown (KeyCode.X) && bomb_nr >= 2) {
            Instantiate (bomb, player.transform.position + new Vector3 (1, 1, 1), Quaternion.identity);
        }
}
  1. Please use code tags when posting code.

  2. Your code works correctly, spawning on the frame X is pressed as long as bomb_nr is greater than or equal to 2.

1 Like

My problem is that when i press x it doesn’t spawn anything. I tryed restarting unity.

Make sure you have the script on an active GameObject, and the inspector is filled out (with a bomb_nr value greater than 1).

I’ve copied and pasted the script and it works fine.

1 Like

I’ve opened it in another project and it works. In the current project it doesn’t.