- Home /
smoke in front of gun when shoot :(
Hi, someone can tell me how i put a smoke in front of the gun when i shoot
if(Input.GetButton("Fire1"))
{
Script here please
}
In C# please but if you dont know in C#, create in JS :C
If the question has been answered, please accept it!
im amazed by the unity communities willingness to program for people who make no attempt to learn program$$anonymous$$g. :P
@$$anonymous$$roductions1, the OP never marks any answers to his questions correct.
@sparkzbarca, I wish I can vote more than once.
HEY @asdf123 , how about you learn how to use Unity Answers, and give some credit to those that give their own time for no pay just to help you.
WATCH : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers
Support the 'site that has been supporting you, and give credit where credit is due.
O$$anonymous$$G I've never saw so much support to answerers
what can I say I feel bad helping for not even thanks
so usually I try asking when I really don't know how to move forward in program$$anonymous$$g that happens very rarely
and I very much upvote any answer I see that's correct
this kind of community support gives me some morale to answer some Q even if I could use that time for my own program$$anonymous$$g
Answer by fjalla · Mar 17, 2013 at 06:42 PM
By the way Javascript version of it is:
var smoke : GameObject;
var endOfGun : Transform;
function Update () {
if(Input.GetButton("Fire1")) {
Instantiate(smoke,
endOfGun.transform.position,
endOfGun.transform.rotation)
}
}
But you probably need the smoke to dissapear after a time so put this on it:
function Start () {
yield WaitForSeconds(5); //waits for 5 seconds
Destroy(gameObject) //then destroys the smoke
}
when i start the game, after 1 second the camera disables and the game stop running :/
The second part is wrong, you should use:
function Start(){
Destroy(gameObject,5.0f);
}
or even better the particle asset from Unity has a script to attached to particle system to destroy them automatically on completion.
when the smoke destroys the camera and the game stop running :/
Answer by fafase · Mar 17, 2013 at 05:29 PM
Add an empty game object at the end of your gun
Attach the object to the gun
Create a script
Scratch your head
Open up the script
Add the code below
public GameObject particle; public Transform endOfGun; void Update(){ if(Input.GetButton("Fire1")) { Instantiate(particle, endOfgun.position,Quaternion.identity); } }
This is it
Try the game
List item
You are getting Null reference exceptions
Get Back on the forum
Post I get a NullReference Please fix my code
Then someone answers "Have you dragged and drop the prefab and the object in the Inpsector"
You answer "No"
You do it
It works perfectly
can... only... upvote... once... aaaaargh
To expand a little on this answer, you can probably just use a flat plane with a smoke picture on it as your smoke prefab, but you could also use Unity's particles. Before you ask how to do these, do a thorough search, because they have both been asked to death.