Question by
Quasiparticle · Aug 13, 2020 at 09:43 AM ·
fpsparticlesystemparticle systemgetbuttonmuzzleflash
Particle System only playing on start and end of GetButton()
0
I'm making an FPS and below is my GunScript:
public float damage = 10f;
public float range = 100f;
public float fireRate = 5f;
public float impactForce = 30f;
public Camera playerCam;
public ParticleSystem muzzleFlash;
public GameObject impactEffect;
private float nextTimeToFire = 0f;
// Start is called before the first frame update
void Start()
{
}
// 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(playerCam.transform.position, playerCam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
Target target = hit.transform.GetComponent<Target>();
if (target != null)
{
target.TakeDamage(damage);
}
if (hit.rigidbody != null)
{
hit.rigidbody.AddForce(-hit.normal * impactForce);
}
Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
}
}
} However the particle system only plays when I push down my mouse or lift up on my mouse. It should play continuously when my mouse is pushed down. Please help me and thanks in advance. ,0
I'm making an FPS and below is my GunScript:
{ public float damage = 10f; public float range = 100f; public float fireRate = 5f; public float impactForce = 30f;
public Camera playerCam;
public ParticleSystem muzzleFlash;
public GameObject impactEffect;
private float nextTimeToFire = 0f;
// Start is called before the first frame update
void Start()
{
}
// 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(playerCam.transform.position, playerCam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
Target target = hit.transform.GetComponent<Target>();
if (target != null)
{
target.TakeDamage(damage);
}
if (hit.rigidbody != null)
{
hit.rigidbody.AddForce(-hit.normal * impactForce);
}
Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
}
}
} However the particle system only plays when I push down my mouse or lift up on my mouse. It should play continuously when my mouse is pushed down. Please help me and thanks in advance.
Comment