Unity2D-如何围绕圆运动和旋转粒子系统?

问题描述 投票:0回答:1

我正在尝试实例化雨滴系统以遵循圆形路径。云团绕圆形行星旋转并运动得非常好。当实例化粒子系统时,无论在何处生成,它几乎永远不会具有正确的旋转,从而产生问题。我试图将这些粒子当作云的孩子,但是那也不起作用。

这里是我实例化的地方-这适用于任何给定的云:

void UpdateCloudState(){
        if(isRaining == true){
            Sprite.color = new Color(.2f,.2f,.2f,1f);
            if(!isInstantiated){
                rain = Instantiate(RainParticles, this.transform.localPosition, Quaternion.identity) as GameObject;
                rain.GetComponent<ParticleSystem>().Play();
                isInstantiated = true;
            }
        }
        else{
            isInstantiated = false;
            Sprite.color = new Color(1f,1f,1f,1f);
            rain.GetComponent<ParticleSystem>().Stop();
            Destroy (rain, 1.0f);
            CloudMovement.speed = originalSpeed;
        }
    }

UPDATE:经过广泛的测试,我发现通过脚本实例化“粒子系统”时,问题只存在于此。

-我发现的解决方案:我将一个空的预制件作为粒子系统的父级,然后将其全部制成1个预制件。

-我将“ Cloud Movement”脚本(绕一圈移动和旋转的脚本)应用于该新的预制件,现在可以使用了

-但是,当我实例化它时,它仍然无法通过脚本工作。

c# unity3d rotation particle-system
1个回答
0
投票

我为我的特定问题找到了替代解决方案。我仍然不知道如何通过实例化它来使其工作。我必须使用粒子系统作为它的子对象来创建一个空的游戏对象,然后将该新的预制件附加到云预制件上。并在脚本中:

void Start()
    {
        Sprite = gameObject.GetComponent<SpriteRenderer>();
        originalSpeed = this.gameObject.GetComponent<CloudMovement>().speed;
        StartCoroutine(StormCoroutine());
        stormLength = 10;
        currentPlanet = GameObject.Find("BigPlanet").transform;
        ////////////////////////////////////////////////////////////
        /////////////////This is the first step of the fix//////////
        ////This line sets 'rain' to the particle system/////
        rain = gameObject.transform.GetChild(0).GetChild(0).gameObject;
    }

void UpdateCloudState(){
        if(isRaining == true){
            Sprite.color = new Color(.2f,.2f,.2f,1f);
            if(!isInstantiated){
                ////////////////////////////////////////////////////////////
                ////This if statement accesses the rain object and plays the particles when necessary///
                rain.GetComponent<ParticleSystem>().Play();
                isInstantiated = true;
            }
        }
        else{
            isInstantiated = false;
            Sprite.color = new Color(1f,1f,1f,1f);
            rain.GetComponent<ParticleSystem>().Stop();
            this.gameObject.GetComponent<CloudMovement>().speed = originalSpeed;
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.