x


Make that muzzle flash? How?

Hello :}

Okay so I'm attempting to create a FPS game set within space. At a stage where code needs to be implemented. Trying to figure out how to make a muzzle flash? I've made a plane so far and don't know what is additional required in terms of code?

Help anyone?

Thanks :}

more ▼

asked Dec 02 '10 at 10:00 AM

Daniele gravatar image

Daniele
116 15 16 21

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You can create muzzle flashes easily by using textured planes in front of the camera. Alternatively you can use animated meshes, or particle effects. No matter which effect you will choose, you can show the effect by using a simple script that is sitting on the muzzle gameobject like:

public class MuzzleFlash : MonoBehaviour
{
    private float _muzzleFlashEnd = 0;

    public void Show(float time)
    {
        //enable renderer/animations
        gameObject.SetActiveRecursively(true);

        //add some variations
        transform.localRotation = Quaternion.Euler(0, 0, Random.Range(0, 360));

       //set a duration for the effect
        _muzzleFlashEnd = Time.time + duration;
    }

    private void Update()
    {
        if (_muzzleFlashEnd < Time.time)
        {
            gameObject.SetActiveRecursively(false);
        }
    }
}

Now activate the effect by something like

if(input.GetMouseButtonDown(0))
{
   _myMuzzleFlash.Show(0.1f);
}

The gameobject will activate and deactivate itself when the effect is over. That way it will not consume any resources when not in use.

more ▼

answered Dec 02 '10 at 11:27 AM

Tommynator gravatar image

Tommynator
381 3 4 11

Its says reference script on this behaviour is missing? Did I do something wrong ;/ I created the gameObject and linked with new script...

Dec 02 '10 at 11:47 AM Daniele
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1169
x274
x181
x176
x24

asked: Dec 02 '10 at 10:00 AM

Seen: 2144 times

Last Updated: Dec 02 '10 at 10:00 AM