Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 teal_dragon · Oct 27, 2016 at 06:48 PM · c#particleslistarrays

how to control particles along a path?

Greetings unity community, i am trying to script a particle path to represent the flow of electricity through a wire with different pathways that can be placed at random. in essence its just a path follow script. currently i have 3 points that represent connection and a way to chose what point the particle should go to next. the main problem i am having is that after i stop the particle flow errors occur in the pathways and particles go all over the screen. i tried to solve this by "binding" each particle to the point it needs to go to next but this hasn't helped at all. with the code provided can someone help me to find either a more efficient method to accomplish this or find were the errors are occurring?

using UnityEngine; using System.Collections;

public class ParticleControl : MonoBehaviour { //different veriables that are used in the simulation public float Offset; public float Speed; public float Emission; float NextTime; public GameObject[] Node; int Alive; bool StartSim = false;

 ParticleSystem Parts;
 ParticleSystem.Particle[] PList;

 int[] List;

 // Use this for initialization
 void Start () 
 {
     Parts = GetComponent<ParticleSystem> ();
     PList = new ParticleSystem.Particle[Parts.maxParticles];
     List = new int[PList.Length];
 }
 
 // Update is called once per frame
 void Update () 
 {
     // controlling the emission rate of the particle system
     if (NextTime <= Time.time && StartSim) 
     {
         Parts.Emit (1);
         NextTime += Emission;
     }
     // starting and stoping
     if(Input.GetKeyDown(KeyCode.Space))
         StartSim = !StartSim;
     // getting the number of particles that are active
     Alive = Parts.GetParticles(PList);
     for (int R = 0; R < Alive; R++) 
     {
         // if the particle just started set its path point to 0: the first point in the node list
         if (PList [R].startLifetime - PList[R].lifetime < 0.1)
             List [R] = 0;
         // tell the particle to head to its bounded node point List[R] keeps track of the points, Node[] holds all possible nodes
         PList [R].velocity = Vector3.Normalize(Node [List[R]].transform.position - PList[R].position) * Speed;
         // if the particle has reached its bounded node point deturmin the next node
         if (PList [R].position.x >= (Node [List [R]].transform.position.x - Offset) && PList [R].position.x <= (Node [List [R]].transform.position.x + Offset)) 
         {
             if (List [R] == 0)
                 List [R] = Random.Range (1,3);
             else if (List [R] == 1)
                 List [R] = 2;
             else if (List [R] == 2)
                 List [R] = 3;
             // if the node reached is the last node terminate the particle that reached it
             else if (List [R] == 3) 
             {
                 PList [R].lifetime = 0;
                 List [R] = 0;
             }
         }
     }
     // set the paramters for the particles
     Parts.SetParticles (PList, Alive);
 }

}

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

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to store gameobjects with specific scripts in a list ? 1 Answer

Multiple Cars not working 1 Answer

Query with C# arrays and List<> 2 Answers

How to modify array values? 1 Answer

A node in a childnode? 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