Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Help with Particles

Discussion in 'Scripting' started by Nubz, Oct 16, 2014.

  1. Nubz

    Nubz

    Joined:
    Sep 22, 2012
    Posts:
    553
    I am using Unity 3.5 anything newer doesn't run on this old pig of a computer.
    First here is an example of what I am doing.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Bubbles : MonoBehaviour
    5. {
    6.  
    7.     void Start()
    8.     {
    9.         gameObject.particleEmitter.emit = false;
    10.     }
    11.  
    12.  
    13.     void Update()
    14.     {
    15.         if (Input.GetKeyDown(KeyCode.B))
    16.         {
    17.             gameObject.particleEmitter.emit = true;
    18.         }
    19.         if (Input.GetKeyUp(KeyCode.B))
    20.         {
    21.             gameObject.particleEmitter.emit = false;
    22.         }
    23.     }
    24.  
    25. }
    Not sure if I need this in there or not since it works with or without it

    Code (CSharp):
    1. void Start()
    2.     {
    3.         gameObject.particleEmitter.emit = false;
    4.     }

    So I am trying to figure out how I could use more than one in the same script assigned to different keys or actions(I think o_O).
    Not sure how to even ask what I am thinking.
    Sort of like finding objects by their tag or name and using sepperrate keys for each one.

    If that makes any sense at all to anyone haha.
    Thank you for any help and I'm not above figuring it out for myself after being pointed in the right direction.
     
    Last edited: Oct 16, 2014
  2. djfunkey

    djfunkey

    Joined:
    Jul 16, 2012
    Posts:
    201
    Im guessing you mean that:
    You want multiple particle systems attached to the same script and you can toggle them on or off at will, and also swap them?

    If this is the case, try using an array to hold all your particles. That should start you on the right track
     
  3. Nubz

    Nubz

    Joined:
    Sep 22, 2012
    Posts:
    553
    Swap them?
    Everything but that is what I meant.
    Not sure what you were getting at by swap unless you mean use different keys/buttons for each one.

    Anyway I'll look into doing it with an array.
    Was having one of those brainfart days and just couldn't find the right words to use for a search lol.
    I'll post again if i figure it out or not thank you for the help regardless of the outcome on my end haha.
     
  4. djfunkey

    djfunkey

    Joined:
    Jul 16, 2012
    Posts:
    201
    Once I get home from school ill wright up some example code for you and give some links.
    Also my response wasn't the best :/
     
  5. djfunkey

    djfunkey

    Joined:
    Jul 16, 2012
    Posts:
    201
    This is a basic script which I wiped together, I haven't tested it out, so all things may not work. Its basically to give you an idea ;)

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class NewBehaviourScript : MonoBehaviour {
    5.  
    6.     public GameObject[] particleSystems;
    7.     public int i;
    8.  
    9.     // Use this for initialization
    10.     void Start () {
    11.         foreach (GameObject g in particleSystems) {
    12.             g.GetComponent<ParticleEmitter>().emit = false;
    13.         }
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update () {
    18.         if (Input.GetKeyDown (KeyCode.B)) {
    19.             ParticleChanger(false);
    20.             particleSystems[i].particleEmitter.emit = true;
    21.         }
    22.         if (Input.GetKeyUp (KeyCode.B)) {
    23.             ParticleChanger(true);
    24.             particleSystems[i].particleEmitter.emit = false;
    25.         }
    26.     }
    27.  
    28.     public bool ParticleChanger (bool enabled) {
    29.         if (enabled) {
    30.             if (Input.GetKeyDown (KeyCode.A)) {
    31.                 i++;
    32.             }
    33.             if (Input.GetKeyUp (KeyCode.S)) {
    34.                 i--;
    35.             }
    36.         }
    37.         return enabled;
    38.     }
    39. }
     
  6. Nubz

    Nubz

    Joined:
    Sep 22, 2012
    Posts:
    553
    Whether it works or not it's at least a starting point for me to work on and I see how the array works now.
    Thank You very much for your help.