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

How do I get total duration of a particle prefab

Discussion in 'Scripting' started by nicklowkc1, Oct 28, 2021.

  1. nicklowkc1

    nicklowkc1

    Joined:
    Feb 27, 2019
    Posts:
    28
    I know it is easy to use GetComponent to get the duration of a particle prefab if Particle system is directly attached to the parent. But how do I get the total duration if the parent has a lot of child with particle system attached to each of them?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    You should drag the one you want into a public ParticleSystem variable.

    If you want to get all of them you can use GetComponentsInChildren<T>() and iterate them yourself.
     
  3. nicklowkc1

    nicklowkc1

    Joined:
    Feb 27, 2019
    Posts:
    28
    Hi, thanks for reply.
    It seems like I have to iterate all over the children. I thought there will be alternate way or easier way.