Hey guys, I’m trying to make a Simple shooting game. I want to spawn a object at the end of the gun, you know the place where the bullet comes out ;). I’ve made up a simple particle that can be used for this. Now my question is. How to make the particle that I’ve created to spawn at the end of the gun continuously until the mouse button is released. Yeah, I wonna make the light like thing appear when shooting. I just want the script for spawning this object. Please give me the script as simple as possible, 'cause I need to see how it works and I’m new to programming. Oh! And the script should be Java. Thanks in Advance.
randomperson is referring to the scripting language in unity called “javascript” isn’t anything like “java” (specifically the language called Java by oracle).
it’s not even the “javascript” used elsewhere outside unity… it’s usually better to refer to it as “unityscript”.
I need to spawn a “Particle” at the end of the Gunbarrel. I’ve created a empty object name “Gun Barrel” at the place where I need the Particle to spawn. And I’ve finished the particle. I wants to know how to spawn this particle in the Empty Game Object named “Gun Barrel” when the mouse is pressed and until the mouse button is released.
And this is what I’ve written so far.
var barrelEnd : Transform;
var gunFire : Particle;
function update () {
if(Input.GetButtonDown("Fire1")){
var fireInstance : Particle;
fireInstance = Instantiate(gunFire, barrelEnd.position, barrelEnd.rotation);
fireInstance.AddForce(barrelEnd.forward * 5000);
}
I know there are many mistakes in it. Help me correct them and complete the sript.
You can spawn particles just like normal bullet prefabs. Make a prefab of your flash particle, instantiate it when you shoot a bullet and immediately destroy the created effect.
TL;DR You can use ‘Instantiate’ for spawning particles.
I used a var sound : audioclip wrote after the particle lines. when I write audio.play(sound); a error shows. but when used audio.playoneshot(sound); the sound plays but half finished.
Begging for code does not work. You need to figure it out for yourself. What you want is one of the easy parts of making a game. If you can’t figure out how to do this, then this is not for you.
Google tutorials for it! And youtube them! There’s a loooot.
As for the audio thing, if you only have one audio attached you don’t need to type audio.Play(sound), just write audio.Play();