Flamethrower in 2D?

I have top-down shooter (Something like dead frontier) and i want to make a flamethrower but i dont know how so please if you know how then please help me. I know i have to have a particle emitter but i dont know how to make the scripts. I have a basic gun that shoots and i used this script:

using UnityEngine;
using System.Collections;

public class BulletScript : MonoBehaviour {
    private float moveSpeed = 30f; 
    private float timeSpentAlive; 
    private GameObject objPlayer;
    private VariableScript ptrScriptVariable;

    // Use this for initialization
    void Start () {
        objPlayer = (GameObject) GameObject.FindWithTag ("Player");
        ptrScriptVariable = (VariableScript) objPlayer.GetComponent( typeof(VariableScript) );
    }

    // Update is called once per frame
    void Update () {
        timeSpentAlive += Time.deltaTime;
        if (timeSpentAlive > 1) 
        {
            removeMe();
        }
        // move the bullet
            transform.Translate(0, 0, moveSpeed * Time.deltaTime);
            transform.position = new Vector3(transform.position.x,0,transform.position.z); // because the bullet has a rigid body we don't want it moving off it's Y axis
    }
    void removeMe ()
    {
        Instantiate(ptrScriptVariable.parBulletHit, transform.position, Quaternion.identity );
        Destroy(gameObject);
    }
    void OnCollisionEnter(Collision Other)
    {
        if ( Other.gameObject.GetComponent( typeof(AIscript) ) != null && Other.gameObject != objPlayer ) // if we have hit a character and it is not the player
        {
            AIscript ptrScriptAI = (AIscript) Other.gameObject.GetComponent( typeof(AIscript) );
            ptrScriptAI.health -= 10;
            Instantiate(ptrScriptVariable.parAlienHit, transform.position, Quaternion.identity );
            removeMe();
        }
        removeMe(); // remove the bullet if it has hit something else apart from an enemy character
    }
}

You are absolutely correct that you need a particle emitter for this :) Lets take a look at it together, but you need to finish it yourself.

  1. Add the "flame thrower" from GameObject -> Create Other -> Particle System.
  2. Lets set some test values:

    • Ellipsoid Particle Emitter:
    • Emit = false
    • Min Size = 0.5
    • Max Size = 0.7
    • Min Energy = 0.8
    • Max Energy = 1.0
    • Min Emission = 10
    • Max Emission = 13
    • Local Velocity = (0, 0, 2)
    • Ellipsoid = (0, 0, 0)
    • Particle Animator
    • Size grow = 3
    • Colors = Give it some cool flame colors or try the standard assets for flames
    • Particle Renderer
    • Cast/Receive shadows = false
  3. We should have some sort of primitive flame thrower now, but we still need to turn it on/off, so how about some scripting:

```

using UnityEngine;
using System.Collections;</p>
`public class FlameThrower : MonoBehaviour
{
    private ParticleEmitter particleEmitter = null;
    private ParticleAnimator particleAnimator = null;  

    void Awake()
    {
        // Get the particle emitter or add it
        particleEmitter = GetComponent();

        if (!particleEmitter)
            particleEmitter = gameObject.AddComponent();

        // Get the particle animator or add it
        particleAnimator = GetComponent();

        if (!particleAnimator)
            particleAnimator = gameObject.AddComponent();
    }

    void Update()
    {
        if (Input.GetButton("Fire1"))
            particleEmitter.emit = true;
        else if (Input.GetButtonUp("Fire1"))
            particleEmitter.emit = false;
    }
}

```

`

  1. Hm, how to detect damage. Well one way of doing it is to use some sort of collider/trigger for it. Turn on/off a box collider, which is the same size of the flames should do it. To detect damage we then use `OnCollisionEnter(...) or OnCollisionStay(...)`.

Hope this helps you on your way :)