我正在尝试实例化雨滴系统以遵循圆形路径。云团绕圆形行星旋转并运动得非常好。当实例化粒子系统时,无论在何处生成,它几乎永远不会具有正确的旋转,从而产生问题。我曾尝试将这些粒子当作云的孩子,但是那也不起作用。
在这里我将其实例化-这将应用于任何给定的云:
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;
}
}
更新 : 经过广泛的测试,我发现通过脚本实例化“粒子系统”时,问题只存在于此。
-我发现的一个修正:我将一个空的预制件作为粒子系统的父级,然后将其全部制成1个预制件。
-我将Cloud Movement脚本(可绕圆移动和旋转的脚本)应用于该新的预制件,现在可以使用
-但是,当我实例化脚本时,它仍然无法通过脚本工作。
答案 0 :(得分: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;
}
}