How do i make my gun model shoot?

Okay i have a gun model with two scripts a aiming script and a movement script it lets me aim and it moves normally i just need it to fire bullets. For example i have seen tutorials where they have a cube with the mesh render off and they add a type of script that makes a bullet spawn there and respawns after a number of seconds. Okay is there any way i can make it shoot just like what the titles says. Thank you so much!

I’m guessing your new to scripting. Well, before you go into making a real game, you should at least know how to script decently. To learn scripting find a tutorial. There are hundreds of unity tutorials (many are outdated now, but they should still work). Also, use the scripting reference It will be vital to any scripting success.

Now to answer your question. Honestly, I think this is a pretty common question. I’m sure I’ve answered one like this before… Anyways, to make something fire an object, you want to instantiate it at a spawn point that you define. Normally, the bullet that you will spawn is a rigidbody. Use rigidbody.velocity to make it move fast. That’s pretty much it, as long as you know what you are doing. Here’s an example:

var bullet : GameObject;
var spawnPoint : Transform;

function Update () {
	if(Input.GetKeyDown("mouse0") {
		var nBullet = Instantiate(bullet, spawnPoint.position, spawnPoint.rotation);
		nBullate.rigidbody.velocity = spawnPoint.TransformDirection(Vector3(0,0,100));
	}
}

That’s about it. I hope you decide to learn how to script. If you decide to make games, you probably need to know at least the basics. Good Luck! :slight_smile:

thank you so much. i am used to scripting and programming i just have not found any tutorials on learning it and i’m very aware that scripting is needed to make a game and thank you so much again i know that you have to instantiate a game object its that i’m very new to scripting NOT the game engine i understand pretty much all the basics of it but scripting. THANK YOU SO MUCH MEATER6