http://bbs.9ria.com/thread-145721-1-1.html
using UnityEngine;
using System.Collections;
public class DParaticle : MonoBehaviour {
private GameObject paraticle;
private int paraticleID = 0;
void OnGUI()
{
if(GUI.Button(new Rect(10,10,100,20),"清除粒子"))
{
paraticleID = 1;
}
if(GUI.Button(new Rect(10,30,100,20),"开启粒子"))
{
paraticleID = 2;
}
}
void Start ()
{
paraticle = GameObject.Find("Particle");
}
void Update()
{
if(paraticleID == 1)
{
//enabled为false的时候暂停粒子,并清除
paraticle.particleEmitter.enabled = false;
if(paraticle.particleEmitter.enabled == false)
{
//清除粒子
paraticle.particleEmitter.ClearParticles();
}
}
else if(paraticleID == 2)
{
//开始粒子
paraticle.particleEmitter.enabled = true;
}
}
}
下面的方法也能实现粒子的开启,和关闭
if(paraticleID == 1)
{
paraticle.transform.particleEmitter.emit = false;
}
else if(paraticleID == 2)
{
paraticle.transform.particleEmitter.emit = true;
}
using UnityEngine;
using System.Collections;
public class DParaticle : MonoBehaviour {
private GameObject paraticle;
private int paraticleID = 0;
void OnGUI()
{
if(GUI.Button(new Rect(10,10,100,20),"清除粒子"))
{
paraticleID = 1;
}
if(GUI.Button(new Rect(10,30,100,20),"开启粒子"))
{
paraticleID = 2;
}
}
void Start ()
{
paraticle = GameObject.Find("Particle");
}
void Update()
{
if(paraticleID == 1)
{
//enabled为false的时候暂停粒子,并清除
paraticle.particleEmitter.enabled = false;
if(paraticle.particleEmitter.enabled == false)
{
//清除粒子
paraticle.particleEmitter.ClearParticles();
}
}
else if(paraticleID == 2)
{
//开始粒子
paraticle.particleEmitter.enabled = true;
}
}
}
下面的方法也能实现粒子的开启,和关闭
if(paraticleID == 1)
{
paraticle.transform.particleEmitter.emit = false;
}
else if(paraticleID == 2)
{
paraticle.transform.particleEmitter.emit = true;
}