Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Particle Effects keep on looping, despite Looping being disabled.

Discussion in 'Animation' started by MiloRoban, Nov 25, 2019.

  1. MiloRoban

    MiloRoban

    Joined:
    Apr 19, 2017
    Posts:
    70
    Hey everyone, I am sorry in advance if this isn't the correct forum (please direct me to the correct one if it is not), but I am running into an issue where in my FPS game, whenever I right click to fire my rifle, the muzzle flash continuously fires even when I am not holding down the right button. Looping is disabled and everything. Any help would be greatly appreciated.

    Here is my script

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Gun : MonoBehaviour {
    4.  
    5.     public float damage = 10f;
    6.     public float range = 100f;
    7.  
    8.     public Camera fpsCam;
    9.     public ParticleSystem muzzleFlash;
    10.     // Update is called once per frame
    11.     void Update() {
    12.         if (Input.GetButtonDown("Fire1"))
    13.         {
    14.             Shoot();
    15.         }
    16.     }
    17.  
    18.     void Shoot ()
    19.     {
    20.         muzzleFlash.Play();
    21.         RaycastHit hit;
    22.         if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
    23.         {
    24.             Debug.Log(hit.transform.name);
    25.  
    26.           Target target =  hit.transform.GetComponent<Target>();
    27.             if (target != null)
    28.             {
    29.                 target.TakeDamage(damage);
    30.             }
    31.         }
    32.     }
    33. }
    34.  

    Any help is greatly appreciated. Thanks!