粒子的控制包括开启、关闭和清除粒子,大致思想就是在添加粒子系统之后利用脚本在OnGUI函数中的Button事件来进行这三个功能的选择,一言不和就贴代码:
using UnityEngine;
using System.Collections;
public class ParticleControl : MonoBehaviour {
private GameObject particle;
private int particleID = 0;
void OnGUI()
{
if(GUI.Button(new Rect(100,100,100,10),"Clear")) particleID = 1;
if(GUI.Button(new Rect(100,200,100,10),"Start")) particleID = 2;
}
void Start ()
{
particle = GameObject.Find("Particle");
}
void Update()
{
if(particleID == 1) {
//enabled为false的时候暂停并清除粒子
particle.particleEmitter.enabled = false;
if(particle.particleEmitter.enabled == false) {
//清除粒子
particle.particleEmitter.ClearParticles();
}
}
else if(paraticleID == 2) {
//开启粒子
paraticle.particleEmitter.enabled = true;
}
}
}