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 zero3growlithe · Jan 22, 2012 at 01:09 PM · arraygameobjects

How to create an array out of many gameObjects?

So I have 12 Particle Emitters which are drag-n-droped onto inspector and I want to make an array out of them to make Unity cache them in memory (I suppose it works that way?). Code looks like this and works quiet slow (lags for half second by 5-10 sec step)

 var ShipEnergyVar : float = 100.0;
 var Destroyer : GameObject;
 var LeftCollisionRay = Vector3(0,0,0);    private var LeftCollisionRayDir = Vector3(-0.05,0,2);
 var RightCollisionRay = Vector3(0,0,0); private var RightCollisionRayDir = Vector3(0.05,0,2);
 var L_Particle1 : ParticleEmitter;    var LS_Particle1 : ParticleEmitter;
 var L_Particle2 : ParticleEmitter;    var LS_Particle2 : ParticleEmitter;
 var L_Particle3 : ParticleEmitter; var LS_Particle3 : ParticleEmitter;
 var R_Particle1 : ParticleEmitter; var RS_Particle1 : ParticleEmitter;
 var R_Particle2 : ParticleEmitter; var RS_Particle2 : ParticleEmitter;
 var R_Particle3 : ParticleEmitter; var RS_Particle3 : ParticleEmitter;
 function ShipEnergy(){
     Speed = rigidbody.velocity.magnitude * 0.003;
         if (Physics.Raycast (transform.TransformPoint (LeftCollisionRay), transform.TransformDirection (LeftCollisionRayDir), Hit, 2, layerMask)){
             ShipEnergyVar -= Speed;
             if (Hit.distance < 0.4){
             L_Particle1.emit = true; LS_Particle1.emit = true;
             } 
             if (Hit.distance > 0.6 && Hit.distance < 1.2){
             L_Particle2.emit = true; LS_Particle2.emit = true;
             }
             if (Hit.distance > 1.2){
             L_Particle3.emit = true; LS_Particle3.emit = true;
             }
         }else {L_Particle1.emit = false; LS_Particle1.emit = false;L_Particle2.emit = false; LS_Particle2.emit = false;L_Particle3.emit = false; LS_Particle3.emit = false;}
         if (Physics.Raycast (transform.TransformPoint (RightCollisionRay), transform.TransformDirection (RightCollisionRayDir), Hit, 2, layerMask)){
             ShipEnergyVar -= Speed;
             if (Hit.distance < 0.4){
             R_Particle1.emit = true; RS_Particle1.emit = true;
             }
             if (Hit.distance > 0.6 && Hit.distance < 1.2){
             R_Particle2.emit = true; RS_Particle2.emit = true;
             }
             if (Hit.distance > 1.2){
             R_Particle3.emit = true; RS_Particle3.emit = true;
             }
         }else {R_Particle1.emit = false; RS_Particle1.emit = false;R_Particle2.emit = false; RS_Particle2.emit = false;R_Particle3.emit = false; RS_Particle3.emit = false;}
         if (ShipEnergyVar < 0){
             Instantiate (Destroyer, transform.position, transform.rotation);
             Destroy (gameObject);
         }
 }
Comment
Add comment · Show 2
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 Owen-Reynolds · Jan 22, 2012 at 04:18 PM 0
Share

$$anonymous$$ight help if you said what the code was suppposed to do? The rayCasts makes it look like you have 12 warning lights that flash when you get near an obstacle (but not when you are 0.4 to 0.6 away?)

avatar image zero3growlithe · Jan 22, 2012 at 06:54 PM 0
Share

It's a ship which uses only two raycasts to detect collisions and toggle sparks (sparks are made from those not simulated in space and those that are simulated and left behind) in 6 places.

1 Reply

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

Answer by save · Jan 22, 2012 at 02:46 PM

They will all be cached when you make them into variables. A GO-array is basically a collection of variables under the same roof so it's easier to iterate through them if you need to.

If your emitters are the same you could equally just use one single and reposition it to the point of impact (or what your script does). Have a look at the emit-function.

Anyhow to make them into an array you just do this:

 var particles : ParticleEmitter[];

and reference to them like this:

 particles[int].emit = true;

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 zero3growlithe · Jan 22, 2012 at 06:56 PM 0
Share

I didn't know that I can have such control over particles, and thx for answer!

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

6 People are following this question.

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

Related Questions

Using a number array? 1 Answer

I'm new to Unity and attempting to create an infinite array of cubes. How would I go about doing this? 0 Answers

Deactivated Targets in Shooting Game Cause Score to Never Stop Adding One 1 Answer

Gather all GameObjects with a certain name in a Scene and Apply them to a list? 3 Answers

After days of looking for solutions, what's wrong with my array script? 2 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