尊者 发表于 2012-12-20 18:36

unity3d中2D射击游戏3:粒子效果的添加

本帖最后由 尊者 于 2012-12-20 18:44 编辑

三、粒子效果的添加

1.添加一个粒子效果
GameObject->Create Other->Particle System

2.选择添加进来的Particle System 重命名为explosion
更改属性如下图所示:


(忘记勾选one shot了+_+,记得添加一个声音效果在Particle Animator中有一个Autodestruct的记得勾选上-自动one shot后销毁)
3.添加一个装粒子效果的类prefab 重命名为explosionPrefab
并绑定explosion 删除explosion
4.接下来要将 爆炸的粒子效果在enemy与bullet发生碰撞时触发
选择bulletScript添加var explosion:Transform;绑定explosion 后 在function OnTriggerEnter(otherObject:Collider)->if(otherObject.gameObject.tag=="enemy")方法中添加var tempExplosion:Transform;
tempExplosion=Instantiate(explosion,transform.position,transform.rotation);//显示爆炸的粒子效果坐标
5.如果圆球enemy碰到 cube player发生碰撞效果   并生命lives-1
在PlayerScript中添加如下代码:function OnTriggerEnter(otherObject:Collider)
{
    if(otherObject.gameObject.tag=="enemy")
    {
   
      otherObject.gameObject.transform.position.y=7;//重置enemy的坐标
      
      otherObject.gameObject.transform.position.x=Random.Range(-6,6);
      
      //产生碰撞效果
      var tempExplosion:Transform;
      
      tempExplosion=Instantiate(explosion,transform.position,transform.rotation);
      
      playerLives--;//声明自减
         
                     this.gameObject.transform.position.x=-0.4;//碰撞后重置player的坐标 居中
    }
}如有错误或不明白的问题请回帖!

itheimo 发表于 2012-12-27 13:43

谢谢分享!!!!!!!!!!!!

尊者 发表于 2013-1-5 20:23

源码下载:http://www.u3dchina.com/t-2342-1-1.html

shengbin88 发表于 2013-1-21 09:48

学习学习了

橘子xs 发表于 2013-8-23 11:14


不错 不错 不错{:soso__3922851084632044791_6:}

lichaoder 发表于 2016-7-11 23:11

学习永无止境

bertro 发表于 2017-1-23 09:50


我很懒,只想回复看看,另感谢楼主分享

坚韧的番茄(秦瘦 发表于 2017-2-18 19:06

楼主是超人

质. 发表于 2017-2-18 18:27

真心顶

憨豆先生 发表于 2017-2-18 19:04

说的非常好
页: [1] 2 3 4 5 6 7 8 9 10
查看完整版本: unity3d中2D射击游戏3:粒子效果的添加