游戏开发模块:特效播放完自动销毁

目录

  • 需求
    • 代码

需求

特效播放完毕自动销毁

代码

 public class ParticleAutoDestruction : MonoBehaviour
    {
        private ParticleSystem[] particleSystems;

        void Start()
        {
            particleSystems = GetComponentsInChildren<ParticleSystem>();
        }

        void Update()
        {
            bool allStopped = true;

            foreach (ParticleSystem ps in particleSystems)
            {
                if (!ps.isStopped)
                {
                    allStopped = false;
                }
            }

            if (allStopped)
                GameObject.Destroy(gameObject);
        }
    }

你可能感兴趣的:(面试汇总,游戏开发)