For this example we will create a new project called gun range so that we can easily test our gameplay without having to build and deploy the entire project. Whenever you are making a large play mechanic change to your game, it is often useful to do this in isolation so that you can be more agile in your development. Large projects can get cluttered pretty quickly so it's best to test in simple projects:
As we will attach this entire weapon and its gunfire particle system to the character as a prefab, we want to make sure that we define everything at this point relative to the coordinate system of the prefab. This is so that when it is attached to our character, or other object, it behaves properly.
We just imported a gun model to our scene and aligned it to the Z-axis. We did this relative to the prefabs, coordinate system and not specifically to the game's coordinate system. We did this because we want projectiles being fired along the prefabs Z-axis regardless of what else is going on in the world's coordinate system.
It doesn't really matter which axis you align the weapon to (so long as you adjust your model and scripts), but it makes logical sense to align the weapon so that it is pointed down the Z-axis so that when we fire projectiles they are going down the positive Z. Why? In the traditional orientation for 3d graphics, movement along the positive Z-axis represents things moving away from the camera – so it makes sense to use that here.
We have two approaches that we can use to add a particle system to our weapon. We can either add it directly to our gun's Game Object or we can add a child Game Object to the gun that does the actual emitting. The approach you choose really depends on how much flexibility you need versus your desire to have more objects in the hierarchy.
If you add the particle system directly to the gun's Game Object, the particles will be emitted from the center of the Game Object and that would not be visually correct. The more universal case is to create a Game Object that will serve as the emission point and attach that to a point on the weapon. This is the approach we will use for our project.
3.135.219.78