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 S3TH · Feb 24, 2011 at 10:07 AM · arrayparticles

Accessing individual particles in array?

I'm trying to learn how to access and assign code to individual particles in an array. Say I started with something like the script reference...

    function LateUpdate () {
// extract the particles
var particles = particleEmitter.particles;
for (var i = 0; i < particles.Length; i++) {
// Move the particles up and down on a sinus curve
var yPosition = Mathf.Sin (Time.time) * Time.deltaTime;
particles[i].position += Vector3 (0, yPosition, 0);
// make the particles red
particles[i].color = Color.red;
// modify the size on a sinus curve
particles[i].size = Mathf.Sin (Time.time) * 0.2;
}
// copy them back to the particle system
particleEmitter.particles = particles;
}

This modifies the entire array. What if I want to do something like randomize the x value for each separate particle? I know how to randomize but what I'm struggling with is getting this to be applied to each "array member" individually. I tried taking the "particleEmitter.particles = particles;" line and putting it back into the for loop along with adding [i] to both - (particleEmitter.particles[i] = particles[i];), and it seems to do null out the code in the for loop.

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
0

Answer by Bampf · Feb 24, 2011 at 11:54 AM

You only want to extract the particles into the array, and put the array back into the particle system, one time.

Once you have the array, you can do whatever you want to each element. That's what the loop is doing. It's walking each element of the array and modifying it. You could make that loop skip every other particle, or remove the loop and only change the first particle in the array. It's up to you.

So hopefully you now see that the lines you want to change are entirely inside the loop. Specifically, change these:

// Move the particles up and down on a sinus curve
var yPosition = Mathf.Sin (Time.time) * Time.deltaTime;
particles[i].position += Vector3 (0, yPosition, 0);

to something like:

// Randomize x position
var xPosition = Random.Range(0, 10);
particles[i].position += Vector3 (xPosition, 0, 0);

Note: If the only thing you want to do is randomize starting position of the particles, you may want to consider (instead of your script) editing the particle emitter to get the same effect. For example, you can make the standard ellipsoid emitter long along the X-axis and get random particles that way.

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

Make an Array of Particles emit at the same time 1 Answer

How to detect which exact particle element from a particle system hit a collider? 0 Answers

particle array null refrence 1 Answer

Turn all objects in the array to make same thing 0 Answers

[Shuriken] emitting particles at arbitrary locations 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