Search Unity

Particle Burst on Button Press

Discussion in 'Scripting' started by SuperSparkplug, Mar 23, 2013.

  1. SuperSparkplug

    SuperSparkplug

    Joined:
    Jul 6, 2012
    Posts:
    25
    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:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class particleOnOff : MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.     gameObject.particleSystem.enableEmission = false;
    9.     }
    10.    
    11.     // Update is called once per frame
    12.     void Update () {
    13.         if (Input.GetKeyDown(KeyCode.JoystickButton0)) {
    14.            
    15.             gameObject.particleSystem.enableEmission = true;
    16.         }
    17.        
    18.        
    19.         /*if (gameObject.particleSystem.enableEmission = true  Input.GetKeyDown(KeyCode.JoystickButton0))  {
    20.             gameObject.particleSystem.enableEmission = false;
    21.         }*/
    22.     }
    23. }
    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?
     
    Last edited: Mar 24, 2013
  2. joshimoo

    joshimoo

    Joined:
    Jun 23, 2011
    Posts:
    266
    == Equality operator
    = Assignment operator

    The reason your commented code is not working is that your assigning instead of checking for equality.