Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Particle system question for my fps game.

Discussion in 'Animation' started by Arizen1451yt, Nov 30, 2023.

  1. Arizen1451yt

    Arizen1451yt

    Joined:
    Mar 30, 2023
    Posts:
    10
    I'm making an fps-style game, and for this, knowledge on the particle system is basically required. I'm wondering how to work the particle system at all, but I can learn that elsewhere. I'm asking how to make the particles appear whenever I click, as sparks from the gun the character wields. This will happen once every shot, and I want the sparks to come from the barrel of the gun, and be able to move with the character (To fire from your position, in your camera direction). I don't know much about the particle system in general, but I can learn that on my own, I just needed to know this. I'll probably ask more questions related to my game as I move through development. Any answer much appreciated.
     
  2. MixxusStudio

    MixxusStudio

    Joined:
    May 9, 2014
    Posts:
    53
    One easy way is to create a child object with a particle system component (under your character), place it at the barrel of the gun, make a reference in your script to the particle system, (like... ParticleSystem mypartSys) then use mypartSys.Play(); whenever you want to fire.
    You can adjust the particles speed and direction and much more in the Particle System component settings.
     
  3. Arizen1451yt

    Arizen1451yt

    Joined:
    Mar 30, 2023
    Posts:
    10
    Ok, so should I put the mypartSys.Play(); under the shoot function? Also would just putting mypartSys.Play(); straight into my script work? Or would I have to add some sort of reference or something to it first?
     
  4. MixxusStudio

    MixxusStudio

    Joined:
    May 9, 2014
    Posts:
    53
    You need a reference first, there are alternate ways, don't know how you build your game and functions, but like a private or public ref, if private, use like:
    Code (CSharp):
    1. mypartSys = GetComponent<ParticleSystem>();
    You probably want to uncheck Looping and Play On Awake in the Particle System component.
     
  5. Arizen1451yt

    Arizen1451yt

    Joined:
    Mar 30, 2023
    Posts:
    10
    I fixed some code, but now when I start the game preview, it says there's no particle system attached. When I attach it and click, it plays once, but then it's gone. Why is the object destroyed after being played once?
     
  6. MixxusStudio

    MixxusStudio

    Joined:
    May 9, 2014
    Posts:
    53
    Do you attach it during game preview? Changes (most) made during play will reverse after pressing stop. If it say's there is no particle system attached, you need to make sure the game object you refer to has a particle system, either from the start or before you call it in the code.
     
  7. Arizen1451yt

    Arizen1451yt

    Joined:
    Mar 30, 2023
    Posts:
    10
    There is a particle system attached at all times, but when I start up preview, it changes to say "None (particle system)" and I have to attach it manually
     
  8. Arizen1451yt

    Arizen1451yt

    Joined:
    Mar 30, 2023
    Posts:
    10
    Help me. I accidentally zoomed out way too far on my cam in the editor preview, couldnt find anything, and copied everything over to another project. Now everything is wrong. What do I do? I Dont want to lose my project
     
  9. sergiusz308

    sergiusz308

    Joined:
    Aug 23, 2016
    Posts:
    233
    If you zoomed out too much pick an object you want to focus camera on, in the Hierarchy and from "Edit" top menu click on "Frame Selected".