- Home /
How do I make a gun?
Okay, so I am making a first person shooter in Unity, and I am working on the gun. I have the gun set, I have a muzzle flash, and I have the sound effects and the reloading and stuff like that. Now all I need to do is make it project a particle effect directly in the center of the screen, where the crosshair is. I made a function called particle, and when I shoot, I call that function. I have no clue what to put in there though. I have been looking forever, but I am completely clueless. I have even tried the machinegun.js in the first person shooter tutorial, but still, nothing. Any help would be greatly appreciated.
What is this particle effect? Is it a hit effect or a fire flash? You should create a prefab with your particle effect. The just instantiate this prefab when you shoot where you want :)))
Answer by Rennat · Dec 01, 2010 at 06:09 PM
If you're wanting to simulate a tracer round's light streak I would use a LineRenderer from the tip of the gun to the point where you will hit. Create it then destroy it a frame later.
If you want impact/ricochet sparks, create a prefab with a particle emitter, make it one shot and autodestruct. Then instantiate it at the impact point.
You can get the point where you will hit by using Physics.Raycast
with Camera.ScreenPointToRay
actually if the gun has a particle emmiter (with emit disabled so it doesn't emit at unwanted times) you can use particleEmitter.Emit() see the scripting documentation on particleEmitter. You can Emit using the settings on the emitter or you can set the position, velocity etc.
Your answer
Follow this Question
Related Questions
How do I make a gun project a particle? 1 Answer
How can I decrease accuracy when the gun is fired? 2 Answers
How to add a delay to my script. 3 Answers
Bullets will not fire forwards 1 Answer
musket gun script is not working 3 Answers