- Home /
gun muzzle flashes
ive been making this fps game with unity for quite a while now i have made my own guns and characters and stuff like that but i dont know how to make a muzzle flash or an explosion from my gun when i shoot.
can anyone help me?
Answer by oliver-jones · Nov 28, 2010 at 12:43 PM
What a lot of people do is add a plane just at the end of the muzzle, and apply an image of muzzle flash. Then add a code on your gun somewhere that randomly rotates the plane slightly when your fire to give the effects of ... randomness I guess.
Take a look at the FPS tutorial by Unity - they do the same thing (http://download.unity3d.com/support/resources/files/FPS_Tutorial_2.pdf)
Something like this:
var muzzleFlash : Renderer; private var nextFireTime = 0.0; private var m_LastFrameShot = -1;
// We shot this frame, enable the muzzle flash
if (m_LastFrameShot == Time.frameCount) { muzzleFlash.transform.localRotation =
Quaternion.AngleAxis(Random.Range(0, 359), Vector3.forward); muzzleFlash.enabled = true;
// We didn't, disable the muzzle flash else { muzzleFlash.enabled = false; enabled = false; }
what do you mean by "then add a code on your gun" what sort of code with what on it?
It all explains it in the FPS tutorial (http://download.unity3d.com/support/resources/files/FPS_Tutorial_2.pdf) -- Let me update my post
when i copy the script which you have given me an error comes up saying expecting }, found else
Answer by ArgionOnline · Dec 28, 2010 at 01:14 PM
The reason everyone is coming up with an error is because he didn't have a } at this point in the code: [CODE]
} //<-just added
// We didn't, disable the muzzle flash
else {
muzzleFlash.enabled = false; enabled = false; }
[/CODE]
(Sorry don't know how to do the code box thing yet)
Your answer
Follow this Question
Related Questions
Muzzleflash help 0 Answers
A node in a childnode? 1 Answer
How do i have explosion effect after my object destroyed? 3 Answers
Explosion with Broken Parts Unity3d 1 Answer
fps controller problems 1 Answer