{Newbie here} Anybody know a SIMPLE way to make my sprite/object shoot bullets?

So I’m quite new here and I managed to program a sprite that moves when any of the arrow keys/WASD keys are pressed. Now I want to make it shoot bullets, but in a really simple code that I could understand, preferably with some explanations for the hard coding terms. Thanks! <3 xx

You can instantiate a Prefab you make of your Sprite, which in this case, would be your bullet. On your bullet prefab, you can have a script that will add to its position: `transform.position += transform.forward * Time.deltaTime * 20; //20 can be considered your 'speed'`

make a new object in the scene and name it “bullet”.

``````using UnityEngine;
using System.Collections;

public class NewBehaviourScript1 : MonoBehaviour {

public GameObject thebullet;

public Vector3 dir = new Vector3(0,1,0);// i added a variable to remember what direction player pushed last

float speed = 0.05f;
bool fire=false;

void Start () {
// find the object in the scene and asign it to a variable;
thebullet=GameObject.Find("bullet");
}
void Update () {
//always multiply speed by time. Otherwise things move faster on faster computers!!!!

speed = 10 * Time.deltaTime;
//Ship Movement
if(Input.GetKey("down") || Input.GetKey("s"))
{print ("down");
transform.position = new Vector3 (
transform.position.x,
transform.position.y - speed,
transform.position.z - speed
);

dir= new Vector3(0,-180,0);

}

if (Input.GetKey ("up") || Input.GetKey("w"))
{
this.transform.position = new Vector3 (
this.transform.position.x,
this.transform.position.y + speed,
this.transform.position.z + speed
);
dir = new Vector3(0,0,0);
}

if (Input.GetKey ("left") || Input.GetKey ("a"))
{
this.transform.position = new Vector3 (
this.transform.position.x - speed,
this.transform.position.y,
this.transform.position.z - speed
);
dir = new Vector3(0,-90,0);
}

if (Input.GetKey ("right") || Input.GetKey ("d"))
{
this.transform.position = new Vector3 (
this.transform.position.x + speed,
this.transform.position.y,
this.transform.position.z + speed
);

dir = new Vector3(0,90,0);
}

if (Input.GetKeyDown("space")){
thebullet.transform.eulerAngles=dir;
thebullet.transform.position=transform.position;
fire=true;
}
if (fire) {
thebullet.transform.position=thebullet.transform.position+thebullet.transform.forward*speed*2;
}
}

}
``````