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

  1. Add an empty game object at the end of your gun

  2. Attach the object to the gun

  3. Create a script

  4. Scratch your head

  5. Open up the script

  6. Add the code below

    public GameObject particle;
    public Transform endOfGun;
    void Update(){
        if(Input.GetButton("Fire1"))  
        {
            Instantiate(particle, endOfgun.position,Quaternion.identity);
        }
    }
    
  7. This is it

  8. Try the game

  9. List item

  10. You are getting Null reference exceptions

  11. Get Back on the forum

  12. Post I get a NullReference Please fix my code

  13. Then someone answers “Have you dragged and drop the prefab and the object in the Inpsector”

  14. You answer “No”

  15. You do it

  16. It works perfectly

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
}