Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 BritishGuy · Nov 06, 2014 at 05:17 PM · javagroup

How can i group together ParticleSystems in JS

Hello,

Here is my SpaceShip controller, Its a complete mess at the moment as i am fairly new to scripting but i do have basic understanding, Yet i cant seem to work this out even after hours of googling.

Q. Is there a better way to group together these engines / thrusters into there own category then call them, For example Engines "Engines.enableEmission = true;", Left Thrusters "LeftThrusters.enableEmission = true;" , Right Thrusters "and so on", Rather than the wall of "var"s i have, The way i have it is also problematic as if i have a smaller ship with less engines, i cant fill each particle and get errors, Thanks.

 //Engines
 var LLEngine : ParticleSystem;
 var LEngine : ParticleSystem;
 var REngine : ParticleSystem;
 var RREngine : ParticleSystem;
 //Front Thrusters
 var FRBThruster : ParticleSystem;
 var FRMThruster : ParticleSystem;
 var FRFThruster : ParticleSystem;
 var FLFThruster : ParticleSystem;
 var FLMThruster : ParticleSystem;
 var FLBThruster : ParticleSystem;
 //Top Thrusters
 var TRBThruster : ParticleSystem;
 var TRFThruster : ParticleSystem;
 var TLBThruster : ParticleSystem;
 var TLFThruster : ParticleSystem;
 //Bottom Thrusters
 var BFRThruster : ParticleSystem;
 var BFLThruster : ParticleSystem;
 var BBLThruster : ParticleSystem;
 var BBRThruster : ParticleSystem;
 //Left Thrusters
 var LFBThruster : ParticleSystem;
 var LFTThruster : ParticleSystem;
 var LBBThruster : ParticleSystem;
 var LBTThruster : ParticleSystem;
 //Right Thruster
 var RBTThruster : ParticleSystem;
 var RBBThruster : ParticleSystem;
 var RFTThruster : ParticleSystem;
 var RFBThruster : ParticleSystem;
 
 
 var ForwardSpeed = 1000;
 var ReverseSpeed = 500;
 var StrafeSpeed = 250;
 var TurnSpeed = 25;
     
     function Start () {
     
     }
     
     function Update () {
  
          //Go Forward
          if(Input.GetKey(KeyCode.W)){constantForce.relativeForce.z = ForwardSpeed * Time.deltaTime;
              LLEngine.startSpeed = 1;
              LEngine.startSpeed = 0.5;
              REngine.startSpeed = 0.5;
              RREngine.startSpeed = 1;
          }else{
              LLEngine.startSpeed = 0.2;
              LEngine.startSpeed = 0.05;
              REngine.startSpeed = 0.05;
              RREngine.startSpeed = 0.2;
          //RREngine.enableEmission = false;
          //Go Back
          if(Input.GetKey(KeyCode.S)){constantForce.relativeForce.z = -ReverseSpeed * Time.deltaTime;
              FRBThruster.enableEmission = true;
             FRMThruster.enableEmission = true;
             FRFThruster.enableEmission = true;
             FLFThruster.enableEmission = true;
             FLMThruster.enableEmission = true;
             FLBThruster.enableEmission = true;
              }else{
              FRBThruster.enableEmission = false;
             FRMThruster.enableEmission = false;
             FRFThruster.enableEmission = false;
             FLFThruster.enableEmission = false;
             FLMThruster.enableEmission = false;
             FLBThruster.enableEmission = false;
          constantForce.relativeForce.z = 0;}}
          //Strafe Left & Right
          if(Input.GetKey(KeyCode.E)){constantForce.relativeForce.x = StrafeSpeed * Time.deltaTime;
              LFBThruster.enableEmission = true;
             LFTThruster.enableEmission = true;
             LBBThruster.enableEmission = true;
             LBTThruster.enableEmission = true;
              }else{
              LFBThruster.enableEmission = false;
             LFTThruster.enableEmission = false;
             LBBThruster.enableEmission = false;
             LBTThruster.enableEmission = false;
          if(Input.GetKey(KeyCode.Q)){constantForce.relativeForce.x = -StrafeSpeed * Time.deltaTime;
              RBTThruster.enableEmission = true;
             RBBThruster.enableEmission = true;
             RFTThruster.enableEmission = true;
             RFBThruster.enableEmission = true;
              }else{
              RBTThruster.enableEmission = false;
             RBBThruster.enableEmission = false;
             RFTThruster.enableEmission = false;
             RFBThruster.enableEmission = false;
          constantForce.relativeForce.x = 0;}}
          //Rotate Up and Down
          if(Input.GetKey(KeyCode.D)){constantForce.relativeTorque.y = TurnSpeed * Time.deltaTime;
              LFBThruster.enableEmission = true;
             LFTThruster.enableEmission = true;
             RBTThruster.enableEmission = true;
             RBBThruster.enableEmission = true;
              }else{
              LFBThruster.enableEmission = false;
             LFTThruster.enableEmission = false;
             RBTThruster.enableEmission = false;
             RBBThruster.enableEmission = false;
          if(Input.GetKey(KeyCode.A)){constantForce.relativeTorque.y = -TurnSpeed * Time.deltaTime;
              LBBThruster.enableEmission = true;
             LBTThruster.enableEmission = true;
             RFTThruster.enableEmission = true;
             RFBThruster.enableEmission = true;
              }else{
              LBBThruster.enableEmission = false;
             LBTThruster.enableEmission = false;
             RFTThruster.enableEmission = false;
             RFBThruster.enableEmission = false;
          constantForce.relativeTorque.y = 0;}}
          //Rotate right and left
          if(Input.GetKey(KeyCode.Space)){constantForce.relativeForce.y = StrafeSpeed * Time.deltaTime;
              BFRThruster.enableEmission = true;
             BFLThruster.enableEmission = true;
             BBLThruster.enableEmission = true;
             BBRThruster.enableEmission = true;
              }else{
              BFRThruster.enableEmission = false;
             BFLThruster.enableEmission = false;
             BBLThruster.enableEmission = false;
             BBRThruster.enableEmission = false;
          if(Input.GetKey(KeyCode.LeftControl)){constantForce.relativeForce.y = -StrafeSpeed * Time.deltaTime;
              TRBThruster.enableEmission = true;
             TRFThruster.enableEmission = true;
             TLBThruster.enableEmission = true;
             TLFThruster.enableEmission = true;
          }else{
              TRBThruster.enableEmission = false;
             TRFThruster.enableEmission = false;
             TLBThruster.enableEmission = false;
             TLFThruster.enableEmission = false;
              constantForce.relativeForce.y = 0;}}
  }
 
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
1
Best Answer

Answer by drod7425 · Nov 06, 2014 at 06:05 PM

Haha wow, that is a bit of a mess :)

There are a few approaches you could take with this, but I would make a Thruster class that contains a Particle System and an enumeration of ThrusterLocations (TOP,BOTTOM,FRONT,BACK,LEFT,RIGHT). Something like this (Please excuse me. I'm more comfortable with C#, so I may make some mistakes):

 enum ThrusterLocation{
 TOP,BOTTOM,FRONT,BACK,LEFT,RIGHT
 }
 
 class Thruster extends Monobehaviour{
 
 var particleSystem : ParticleSystem;
 var thrusterLocation : ThrusterLocation[3]; //each of your thrusters had three axes
 
 }

Then I would put that script on each thruster in the scene and assign the appropriate variables in the inspector. Finally, in the script you showed, I'd make an Thruster[] that I could set in the inspector. Like this:

 var thrusters : Thruster[22];
 
 function Update(){
 if(Input.GetKey(KeyCode.S)){
 for(var thruster in thrusters){
 thruster.particleSystem.enableEmission = thruster.thrusterLocation[0]==ThrusterLocation.FRONT;
 }
 }
 //And so on for all the Input keys and their appropriate thrusters
 }

That's just the one way that my mind immediately goes to with this situation. You may want to do something a little or completely different, but I hope this helps!

EDIT: BTW, here are some resources on the concepts that I used in this answer:

http://unity3d.com/learn/tutorials/modules/beginner/scripting/arrays http://unity3d.com/learn/tutorials/modules/beginner/scripting/enumerations http://unity3d.com/learn/tutorials/modules/beginner/scripting/loops http://unity3d.com/learn/tutorials/modules/intermediate/scripting/ternary-operator

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 BritishGuy · Nov 06, 2014 at 06:29 PM 0
Share

Complete mess ain't it lol, that's why i stopped and had to ask here for help before it got out of control haha

Thanks allot for the help, $$anonymous$$uch appreciated.

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

27 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 avatar image avatar image avatar image 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

Convert this line of javascript to C# (easy) 1 Answer

i need some code suggestions 1 Answer

how to stop animation loop? 1 Answer

oescape script name? 1 Answer

Stand alone player 0 Answers


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