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
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
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
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
}