Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by lostframe77 · Apr 06, 2017 at 03:29 PM · scripting problemparticlesystemplayvalue

How to play a ParticleSystem just once when a certain value is reached

Hi, I want to play the Particle system (with children ) just once, when the progress bar reaches 100%. When I use Play method under the Update function, it works, but it loops (I know this is not the right way) . Since I am new to C#, please help me with the code.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class ProgressBarParticleController : MonoBehaviour {
 
     public Transform Progress_Bar;
     public ParticleSystem particleBurst;
 
 
     [SerializeField] private float currentAmount;
     [SerializeField] private float speed;
 
     void Update () {
         if (currentAmount < 100) {
             currentAmount += speed * Time.deltaTime;
             }
 
         // With this statement below the Particle System bursts at the end, but it loops even though Looping is unchecked in the editor
         else {
             particleBurst.Play();
             }
 
         Progress_Bar.GetComponent<Image> ().fillAmount = currentAmount / 100;
     }
 /*
 //    With this statement below nothing happens.
 
 /*     public void ParticleBurst () {
 
         if (currentAmount == 100) {
             particleBurst.Play ();
 //            particleBurst.Emit (30);  
         
         }
     }
 */
 }
 

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by KKS21199 · Apr 06, 2017 at 05:25 PM

Hey,

you can use particleBurst.Emit(); instead of particleBurst.play(); and it should only play once.

You can also use Play by unchecking the Looping option in the inspector and also set the duration to the number of seconds you want the particle to play. (by default it is 5)

  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using UnityEngine.UI;
  
  public class ProgressBarParticleController : MonoBehaviour {
  
      public Transform Progress_Bar;
      public ParticleSystem particleBurst;

      [SerializeField] private float currentAmount;
      [SerializeField] private float speed;
  
      void Update () {
          if (currentAmount < 100) {
              currentAmount += speed * Time.deltaTime;
              }
  
          // With this statement below the Particle System bursts at the end, but it loops even though Looping is unchecked in the editor
          else {
              particleBurst.Emit(100);
              }
  
          Progress_Bar.GetComponent<Image> ().fillAmount = currentAmount / 100;
      }
  }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dnwsaa58 · Sep 26, 2018 at 12:26 PM 0
Share

thanks a lot! unchecking the Looping option doesn't work for me. I use emit();

avatar image
1

Answer by lostframe77 · Apr 07, 2017 at 11:20 PM

@Sugavanas thanks for the answer, but I have tried this before and it didn't work. In the meantime I have found the solution. This code works in my case...

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class ProgressBarParticleBurst : MonoBehaviour {
 
     public Transform Progress_Bar;
     public ParticleSystem particleBurst;
     private bool played;
 
 
     [SerializeField] private float currentAmount;
     [SerializeField] private float speed;
 
 
     void Update () {
         if (currentAmount < 100) {
             currentAmount += speed * Time.deltaTime;
 
         } 
 
         else 
             if (!played) {
                 particleBurst.Play ();
                 played = true;
             }
 
         Progress_Bar.GetComponent<Image> ().fillAmount = currentAmount / 100;
 
     }
 }


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Weird behaiviour with particle system. 1 Answer

Particle System not playing 1 Answer

How to use OnParticleTrigger correct? 4 Answers

Why doesn't changing the particle's mateiral color during runtime work? 0 Answers

Why is Shurikan particle system variable textureSheetAnimation scripting not recognised? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges