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