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?
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);
}
}
}