- Home /
shooting more than 1 bullet
how do i go about shooting more than 1 bullet when i press the fire button, for example like call of duty.
Please be more specific in your posts - do you mean like a L$$anonymous$$G (so on bullet after another) or like Rennat asked, a shotgun? (like a spray)?
Answer by JesusChristChangedMe · Dec 05, 2010 at 08:17 PM
this will tell your game when the left button is held down to keep fireing a bulletprefab. make sure the prefab has a rigidbody and make sure the gun your shooting from has a spawnpoint and it is named exactly "Spawnpoint".you can make a spawnpoint just by making a sphere and making sure the sphere is exactly where you want your bullet to appear. So it would probably be wise to put it in front and close to the barrel of the gun. Also make sure it is a child of the gun. To make it a child of the gun just drag the spawn point in the hierarchy onto the gun in the hierarchy. theres a couple of things that need to be done outside of the script for it to work. make sure your spawnpoint is unchecked mesh renderer and doesnt have a collider.
var bullet : Transform;
function Update()
{
if(Input.GetButton("Fire1"))
{
var bullet = Instantiate(bulletPrefab ,transform.Find("Spawnpoint").transform.position ,Quaternion.identity);
bullet.gameObject.tag = "enemyProjectile";
bullet.rigidbody.AddForce(transform.forward * 2000);
}
}
Hope this helps!
i'm sure UnityScripter meant left $$anonymous$$OUSE button. not left arrow button. just for clarity. Fire1 = left mouse button unless changed in the Input $$anonymous$$anager.
yeah! oops! thanks ill fix that... maybe. probebly not.
when i do everything you have said when i fire my gun the bullets just drop onto the floor ins$$anonymous$$d fire out please help.
Is it when you just face a certain direction it doesn't go anywhere but when you face a different direction it shoots? Try turning around when shooting, like in circles, and see what happens. If it shoots good in some directions and not in others I know how to fix it.
You do have a bullet prefab correct? And it is put in the place where it says bullet-Transform correct in the inspector? There might be an issue with your prefab. Just let me know about the bullets falling on the ground thing and what happened when u faced a different direction.
Your answer
Follow this Question
Related Questions
Bullet does not move forward 1 Answer
A node in a childnode? 1 Answer
Only one of all my Enemies shoots, Help please. 1 Answer
How do I make a 2d bullet object move towards the players original position when it is spawned? 2 Answers
transform.TransformDirection not working -- WHAT IM MISSISNG? 1 Answer