- Home /
Question by
0oSIMONo0 · May 24, 2015 at 02:51 PM ·
muzzleflash
How to add MuzzleFlash?
Hey guys I'm 11 so clearly, I'm a beginner, but I've learned all those basic stuff and trying to make a FPS now, I've been learning Instantiating and Raycast and I decided to use raycast but the problem now is that I can't add the MuzzleFlash, whenever I add it, the Muzzleflash never appear, what should I do? Here's my script :
using UnityEngine; using System.Collections;
public class Gun : MonoBehaviour { public enum FireMode { Auto, Burst, Semi }
//Changing the firemode
public FireMode firemode = FireMode.Auto;
//RPM and firerate
public float FireRate = 0.05f;
public float FireTime;
public bool IsBurst = false;
void Update()
{
if (FireTime <= 0 && !IsBurst)
{
switch (firemode)
{
case FireMode.Semi:
if (Input.GetButtonDown("Fire1"))
{
Fire();
GetComponent<AudioSource>().Play();
FireTime = FireRate;
}
break;
case FireMode.Burst:
if (Input.GetButtonDown("Fire1"))
{
StartCoroutine(BurstFire(FireRate, 3));
GetComponent<AudioSource>().Play();
FireTime = FireRate;
}
break;
case FireMode.Auto:
if (Input.GetButton("Fire1"))
{
Fire();
GetComponent<AudioSource>().Play();
FireTime = FireRate;
}
break;
}
}
if (FireTime > 0)
{
FireTime -= Time.deltaTime;
}
}
void Fire()
{
RaycastHit hit;
Ray ray = new Ray(transform.position, transform.forward);
if (Physics.Raycast(ray, out hit, 100f))
{
}
}
IEnumerator BurstFire(float rate, int rounds)
{
IsBurst = true;
for (int i = 0; i < rounds; i++)
{
Fire();
yield return new WaitForSeconds(rate);
}
IsBurst = false;
}
}
Comment
Your answer
Follow this Question
Related Questions
Instantiating Muzzle Flash 1 Answer
Muzzle Flash 1 Answer
Muzzleflash Question 3 Answers
Why the particle system don't play? 2 Answers
How to make and use a muzzleflash 1 Answer