一、粒子特效 粒子效果的原理是将若干粒子无规则地组合在一起,用来模拟火焰、爆炸、水滴、雾气等效果。 创建粒子对象:Hierachy视图点击create----》particle system即可。创建好粒子对戏对象后,即可在scene视图中编辑该粒子对象的位置。 二、粒子发射器 粒子发射器用于设定粒子的发射属性,比如粒子的大小、数量和速度。在hierarchy视图中选择刚刚创建的粒子对象,在右侧的Inspector视图中可以看到粒子发射器的所有属性。![]() 三、粒子动画 粒子动画用于设定粒子渲染中的动画效果。动画效果的种类繁多,比如动画的颜色、拉伸的比例、拉伸的速度、等粒子动画的属性 ![]() 四、粒子渲染器 粒子渲染器主要用于粒子的渲染,比如粒子渲染模式,粒子的缩放、粒子的尺寸。粒子渲染器中各个选项的具体含义。 ![]() 五、粒子效果实例 Unity提供了粒子标准资源包,其中包含了很多非常棒的粒子资源。下述代码中,首先在start方法中使用find方法获取当前粒子效果的游戏对象,然后继续调用particleEmitter引用拿到当前粒子效果的发射器对象,最后根据发射器对象来编辑粒子效果。 代码有误:MissingComponentException: There is no 'ParticleEmitter' attached to the "ParticleSystem" game object, but a script is trying to access it. using UnityEngine; using System.Collections; public class particle : MonoBehaviour { //例子对象 GameObject particles=null; //粒子在x轴方向的速度 float velocity_x=0.0f; //粒子在y轴方向的速度 float velocity_y=0.0f; //粒子在z轴方向的速度 float velocity_z=0.0f; // Use this for initialization void Start () { particles=GameObject.Find("ParticleSystem"); } void OnGUI() { //通过拖动设置粒子的最大尺寸 GUILayout.Label("粒子最大尺寸"); particles.GetComponent<ParticleEmitter>().maxSize=GUILayout.HorizontalSlider(particles.GetComponent<ParticleEmitter>().maxSize,0.0f,10.0f,GUILayout.Width(150)); this.gameObject.GetComponent<ParticleSystem>().enableEmission=true; particles.AddComponent<ParticleEmitter>(); //通过拖动设置粒子的最大消失时间 GUILayout.Label("粒子消失时间"); particles.GetComponent<ParticleEmitter>().maxEnergy=GUILayout.HorizontalSlider(particles.GetComponent<ParticleEmitter>().maxEnergy,0.0f,10.0f,GUILayout.Width(150)); //通过拖动设置粒子的最大生成数量 GUILayout.Label("粒子的最大生成数量"); particles.GetComponent<ParticleEmitter>().maxEmission=GUILayout.HorizontalSlider(particles.GetComponent<ParticleEmitter>().maxEmission,0.0f,10.0f,GUILayout.Width(150)); //拖动设置x轴的移动速度 GUILayout.Label("粒子x轴的移动速度"); velocity_x=GUILayout.HorizontalSlider(velocity_x,0.0f,10.0f,GUILayout.Width(150)); particles.GetComponent<ParticleEmitter>().worldVelocity=new Vector3(velocity_x,particles.GetComponent<ParticleEmitter>().worldVelocity.y,particles.GetComponent<ParticleEmitter>().worldVelocity.z); //拖动设置y轴的移动速度 GUILayout.Label("粒子y轴的移动速度"); velocity_y=GUILayout.HorizontalSlider(velocity_y,0.0f,10.0f,GUILayout.Width(150)); particles.GetComponent<ParticleEmitter>().worldVelocity=new Vector3(particles.GetComponent<ParticleEmitter>().worldVelocity.x,velocity_y,particles.GetComponent<ParticleEmitter>().worldVelocity.z); //拖动设置z轴的移动速度 GUILayout.Label("粒子z轴的移动速度"); velocity_z=GUILayout.HorizontalSlider(velocity_z,0.0f,10.0f,GUILayout.Width(150)); particles.GetComponent<ParticleEmitter>().worldVelocity=new Vector3(particles.GetComponent<ParticleEmitter>().worldVelocity.x,particles.GetComponent<ParticleEmitter>().worldVelocity.y,velocity_z); } // Update is called once per frame void Update () { } } |
|