您的位置:首页 > 移动开发 > Unity3D

Unity 二战中加飞机

2015-10-27 15:26 169 查看

一个简短的引论:

谢意:

本申请中使用《Unity3D\2D移动游戏开发》提供资源。著作权属于作者。感谢作者。基于原始时本申请的二次开发。

要素:

1.增加2s cd的机身旋转,旋转时保持无敌状态,人挡杀人。。



2.增加0,5s cd的跟踪导弹,导弹随机打击目标敌人。

3.加强小飞机AI,小飞机拥有三种飞行模式,直线。sin曲线,以及追踪玩家。以不同概率随机选择飞行模式。

技术要素:

1.对于玩家飞机。採用简单switch-case有限状态机。

2.对于小飞机AI则使用RAIN AI 行为树。

3.书中源程序包升级为unity5.0。并消除了升级出现Mesh trigger bug。

player部分状态机源代码

void Normal(){
if (Input.GetMouseButton (1)) {
state=PlayerState.Arounding;
}
}
void Shoot(){
m_superRate -= Time.deltaTime;
if (m_superRate <= 0) {
m_superRate=0.5f;
Instantiate (m_srocket, m_transform.position+new Vector3(0.5f,0,0), m_transform.rotation);
Instantiate (m_srocket, m_transform.position+new Vector3(-0.5f,0,0), m_transform.rotation);
}

m_rocketRate -= Time.deltaTime;
if (m_rocketRate <= 0) {
m_rocketRate = 0.1f;

if (Input.GetKey (KeyCode.Space) || Input.GetMouseButton (0)) {
Instantiate (m_rocket, m_transform.position, m_transform.rotation);
m_audio.PlayOneShot (m_shootClip);
}
}
}
void CoolDown(){
m_around -= Time.deltaTime;
if (m_around <= 0) {
m_around = 1f;
state=PlayerState.Normal;
}

}


EnemyAI行为树:



注意事项:

1. plane triangle mesh unity5.0 不支持trigger

2.RAIN AI ai 的body 的transform 是一份复制文件,改动它无法移动游戏对象,能够使用ai.motor.moveto

github地址

https://github.com/RonTang/ShootingGamex/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: