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的坐标 居中
}
}如有错误或不明白的问题请回帖!
谢谢分享!!!!!!!!!!!! 源码下载:http://www.u3dchina.com/t-2342-1-1.html 学习学习了
不错 不错 不错{:soso__3922851084632044791_6:} 学习永无止境
我很懒,只想回复看看,另感谢楼主分享 楼主是超人 真心顶 说的非常好