- Home /
Muzzle flash not showing up at high fire rates
I downloaded War FX (https://assetstore.unity.com/packages/vfx/particles/war-fx-5669) for the muzzle flashes and I followed Brackeys tutorial on unity shooting, but when I raise my fire rate over 10 and hold down fire, the muzzle flash only appears when I let go of the button. Here's the code if any one think they might know the problem.
using UnityEngine;
public class GunScript : MonoBehaviour {
//Gun basics
public float damage = 10f;
public float range = 100f;
public float fireRate = 15f;
private float nextTimeToFire = 0f;
//FPS camera
public Camera fpsCam;
//Gun effects
public ParticleSystem muzzleFlash;
public GameObject impactSand;
public float impactForce = 30f;
// Update is called once per frame
void Update ()
{
if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire)
{
nextTimeToFire = Time.time + 1f / fireRate;
Shoot();
}
}
void Shoot()
{
muzzleFlash.Play();
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
Enemy enemy = hit.transform.GetComponent<Enemy>();
if (enemy != null)
{
enemy.TakeDamage(damage);
}
if (hit.rigidbody != null)
{
hit.rigidbody.AddForce(-hit.normal * impactForce);
}
GameObject ImpactGO = Instantiate(impactSand, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(ImpactGO, 1f);
}
}
}
Answer by TrippyVision · Jul 07, 2020 at 09:32 AM
@OOGABALLOOGA sorry for the very late reply and i think you got the answer but in case you dont or any body who comes here for the answer go to your muzzle flash effect and scroll down to where it says culling mode and switch it from pause and catch up to automatic and i hope i help someone,@OOGABALLOOGA Hi its great to see a fellow from brackeys tutorial, i had the same problem but i found the solution got o your muzzle flash particle effect scroll down to where it says Culling mode and switch from pause and catch up to automatic and i hope i helped you
Answer by JohnnyBoyle2 · Feb 15 at 05:54 PM
The solution that I found was turning the fire rate to 10 or below, for some reason when its higher the muzzle flash doesn't show up. (Also make sure to do this in Unity and not in the code as "fireRate" is a public variable),The solution that I found was turning the fire rate to 10 or below, for some reason when it's higher the muzzle flash doesn't show up. (Also make sure to do this in Unity and not in the code as "fireRate" is a public variable)
Answer by andrew-lukasik · Feb 15 at 06:49 PM
Replace that muzzleFlash.Play();
with:
if( !muzzleFlash.isPlaying || muzzleFlash.time>(1f/muzzleFlash.emission.rateOverTime.constant) )
{
muzzleFlash.Play();
}
Calling muzzleFlash.Play();
every frame is equivalent to calling animation.Play()
or sound.Play()
every frame and the results are always the same: seeing first animation frame only, hearing the first music note only (often a total silence) or seeing only the first ParticleSystem animation frame - which is often nothing at all.
Your answer
Follow this Question
Related Questions
Raycast Decals,Sound and MuzzleFlash not working too well 0 Answers
How to set a firerate on this? 2 Answers
App is not showing on Xcode simulator 1 Answer
muzzle flash and particle emit didn't show when shot 1 Answer
Disabling Simulate in WorldSpace in Ellipsoid Particle Emitter not working! 0 Answers