- Home /
Question by
parmeshwar · Feb 15, 2013 at 03:36 PM ·
spawnpointsgunfirebullet-prefab
How to create spawnPoint for bullet shoot
hello all i am going to develop an 3d game where i want to fire bullets by gun i have searched for fire and also using a simple code for firing the bullet following code is working but i dont know how to create spawnPoint var BulletPrefab :Transform; var force : float = 2;
function Update()
{
if(Input.GetButtonDown("Fire1"))
{ var bullet = Instantiate(BulletPrefab,GameObject.Find("spawnPoint").transform.position,Quaternion.identity);
bullet.rigidbody.AddForce(transform.forward * force);
} }
Comment
Best Answer
Answer by robertbu · Feb 15, 2013 at 04:30 PM
Make an empty game object then rename it to "spawnPoint". Note you want to place this point just in front of your gun barrel and make it a child of the barrel so that it rotates when you aim the gun.