Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 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
2
Question by SuperSparkplug · Mar 24, 2013 at 12:08 AM · particlesparticlesystemshuriken

Particle Burst on Button Press

Hi. I just got over looking a particle systems in Unity and I need help figuring something out.

I'm currently using the Shuriken particle system in Unity 4. I'd like to sync a button press to trigger not only an increase of speed in my particle system, but trigger the particle burst feature. I've looked through the documentation on Unity's website but it's rather incomplete when it comes to Particle Systems. I've tried to code a few things and it's become rather hit or miss as to whether Unity will accept the code for things, though I will admit I'm not the best programmer.

I've been taking a few small steps trying to learn how to program the particle system. So far, the most progress I've had is:

 using UnityEngine;
 using System.Collections;
 
 public class particleOnOff : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
     gameObject.particleSystem.enableEmission = false;
     }
     
     // Update is called once per frame
     void Update () {
         if (Input.GetKeyDown(KeyCode.JoystickButton0)) {
             
             gameObject.particleSystem.enableEmission = true;
         }
         
         
         /*if (gameObject.particleSystem.enableEmission = true && Input.GetKeyDown(KeyCode.JoystickButton0))  {
             gameObject.particleSystem.enableEmission = false;
         }*/
     }
 }

Now I'm using a unique gamepad for this project, the Nintendo DK Bongos, which is why it's reading joystick buttons, though I've also tested this with regular buttons. It works, but it only turns the particles on only. The commented out part is because I wanted to make the bongos turn emission on and off. Problem is that adding that commented part into the code makes it so the particle system won't work at all. Adding a normal if or else statement after the first if statement doesn't seem to work either. I consider this the first step to understanding the particle system, but I'm getting frustrated at getting these bursts to work. Can anyone help me?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by Chronos-L · Mar 24, 2013 at 01:42 AM

Have you took a look at ParticleSystem.Emit( count:int )?

If you need a quick burst of 10 particles when you click

 public class ParticleController : MonoBehaviour {
 
     void Start () {
         // You can use particleSystem instead of
         // gameObject.particleSystem.
         // They are the same, if I may say so
         particleSystem.emissionRate = 0;
     }
     
     void Update () {
         if( Input.GetKeyDown( KeyCode.A ) ) {
             particleSystem.Emit(10);    
         }
     }
 }

if you need X number of particles per second while touching:

 if (Input.GetKey(KeyCode.A)) {
    particleSystem.Emit( (int) (particlePerSecond * Time.deltaTime) );
 }

Comment
Add comment · Show 10 · 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 SuperSparkplug · Mar 24, 2013 at 01:44 AM 0
Share

I have, but when I was fooling around with that parameter, it just refused to work and I moved on to the enableEmission function. If you don't $$anonymous$$d. Could you post an example?

avatar image Chronos-L · Mar 24, 2013 at 01:55 AM 0
Share

enableEmission is more suitable for something like turn on the fire, start falling leaves etc

You are looking for burst, so you should use emissionRate=0 with Emit(count).

I edited my answer, take a look at it. I use the A key to burst particles.

avatar image SuperSparkplug · Mar 24, 2013 at 02:37 AM 0
Share

Holy crap! It works awesomely! Thank you so much! You've saved me so much time and frustration! :D

One thing though:

     if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.A)) {
     particleSystem.Emit( (int) (particlePerSecond * Time.deltaTime) );
     }

I tried editing the int and particlePerSecond parameter with numbers, but I get a series of errors. How exactly particlePerSecond parameter work?

avatar image Chronos-L · Mar 24, 2013 at 03:14 AM 0
Share

It is a parameter from you script.

 public int particlePerSecond = 75;

 ...

 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.A)) {
    particleSystem.Emit( (int) (particlePerSecond * Time.deltaTime) );
 }

By using particlePerSecond * Time.deltaTime, you will get a rough estimation on how many particles should be emitted on that particular Update() so it will fit particlePerSecond.

What errors are you getting?

avatar image SuperSparkplug · Mar 24, 2013 at 03:18 AM 0
Share

Oh, I didn't have a particlePerSecond variable. I added it, but I'm still getting errors.

Assets/Standard Assets/Scripts/particleOnOff.cs(17,30): error CS0119: Expression denotes a value', where a method group' was expected

Assets/Standard Assets/Scripts/particleOnOff.cs(17,20): error CS1502: The best overloaded method match for UnityEngine.ParticleSystem.Emit(int)' has some invalid arguments Assets/Standard Assets/Scripts/particleOnOff.cs(17,20): error CS1503: Argument #1' cannot convert object' expression to type int'

Show more comments

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

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Scale Shuriken Particle System with Parent Transform 5 Answers

Particles emmiting all over the shape, is it possible make them spawn gradually from a set point? 0 Answers

PS Custom Vertex Streams to Particle Trail 0 Answers

Setting the position of particles in a (shuriken) ParticleSystem 3 Answers

Multiple trails behind one particle? 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