Unity3D太空大战Word文件下载.docx

上传人:b****6 文档编号:18888564 上传时间:2023-01-02 格式:DOCX 页数:14 大小:17.35KB
下载 相关 举报
Unity3D太空大战Word文件下载.docx_第1页
第1页 / 共14页
Unity3D太空大战Word文件下载.docx_第2页
第2页 / 共14页
Unity3D太空大战Word文件下载.docx_第3页
第3页 / 共14页
Unity3D太空大战Word文件下载.docx_第4页
第4页 / 共14页
Unity3D太空大战Word文件下载.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

Unity3D太空大战Word文件下载.docx

《Unity3D太空大战Word文件下载.docx》由会员分享,可在线阅读,更多相关《Unity3D太空大战Word文件下载.docx(14页珍藏版)》请在冰豆网上搜索。

Unity3D太空大战Word文件下载.docx

}

//Updateiscalledonceperframe

voidUpdate(){

UpdateMove();

protectedvirtualvoidUpdateMove()

{

m_timer-=Time.deltaTime;

if(m_timer<

=0)

m_timer=3;

//改变旋转方向

m_rotSpeed=-m_rotSpeed;

//旋转方向

m_transform.Rotate(Vector3.up,m_rotSpeed*Time.deltaTime,Space.World);

//前进

m_transform.Translate(newVector3(0,0,-m_speed*Time.deltaTime));

voidOnTriggerEnter(Colliderother)

if(other.tag.CompareTo("

PlayerRocket"

)==0)

Rocketrocket=other.GetComponent<

Rocket>

();

if(rocket!

=null)

m_life-=rocket.m_power;

if(m_life<

GameManager.Instance.AddScore(m_point);

Instantiate(m_explosionFX,m_transform.position,Quaternion.identity);

Destroy(this.gameObject);

elseif(other.tag.CompareTo("

Player"

m_life=0;

bound"

}

 

(2)EnemyRocket的源码:

MyGame/EnemyRocket"

publicclassEnemyRocket:

Rocket

{

)!

return;

(3)EnemySpawn敌人生成器:

MyGame/EnemySpawn"

publicclassEnemySpawn:

MonoBehaviour

//敌人的Prefab

publicTransformm_enemy;

//生成敌人的时间间隔

protectedfloatm_timer=5;

m_timer=Random.value*15.0f;

5)

m_timer=5;

Instantiate(m_enemy,m_transform.position,Quaternion.identity);

voidOnDrawGizmos()

Gizmos.DrawIcon(transform.position,"

item.png"

true);

(4)GameMannager图形界面:

MyGame/GameManager"

publicclassGameManager:

publicstaticGameManagerInstance;

//得分

publicintm_score=0;

//纪录

publicstaticintm_hiscore=0;

//主角

protectedPlayerm_player;

//背景音乐

publicAudioClipm_musicClip;

//声音源

protectedAudioSourcem_Audio;

voidAwake()

Instance=this;

m_Audio=this.audio;

//获取主角

GameObjectobj=GameObject.FindGameObjectWithTag("

);

if(obj!

m_player=obj.GetComponent<

Player>

//循环播放背景音乐

if(!

m_Audio.isPlaying)

m_Audio.clip=m_musicClip;

m_Audio.Play();

//暂停游戏

if(Time.timeScale>

0&

&

Input.GetKeyDown(KeyCode.Escape))

Time.timeScale=0;

voidOnGUI()

//游戏暂停

if(Time.timeScale==0)

//继续游戏按钮

if(GUI.Button(newRect(Screen.width*0.5f-50,Screen.height*0.4f,100,30),"

继续游戏"

))

Time.timeScale=1;

//退出游戏按钮

if(GUI.Button(newRect(Screen.width*0.5f-50,Screen.height*0.6f,100,30),"

退出游戏"

//退出游戏

Application.Quit();

intlife=0;

if(m_player!

//获得主角的生命值

life=(int)m_player.m_life;

else//gameover

//放大字体

GUI.skin.label.fontSize=50;

//显示游戏失败

GUI.skin.label.alignment=TextAnchor.LowerCenter;

GUI.Label(newRect(0,Screen.height*0.2f,Screen.width,60),"

游戏失败"

GUI.skin.label.fontSize=20;

//显示按钮

if(GUI.Button(newRect(Screen.width*0.5f-50,Screen.height*0.5f,100,30),"

再试一次"

//读取当前关卡

Application.LoadLevel(Application.loadedLevelName);

GUI.skin.label.fontSize=15;

//显示主角生命

GUI.Label(newRect(5,5,100,30),"

装甲"

+life);

//显示最高分

GUI.Label(newRect(0,5,Screen.width,30),"

纪录"

+m_hiscore);

//显示当前得分

GUI.Label(newRect(0,25,Screen.width,30),"

得分"

+m_score);

//增加分数

publicvoidAddScore(intpoint)

m_score+=point;

//更新高分纪录

if(m_hiscore<

m_score)

m_hiscore=m_score;

(5)Player主飞船的源码:

MyGame/Player"

publicclassPlayer:

publicfloatm_life=3;

//子弹prefab

publicTransformm_rocket;

//发射子弹频率

floatm_rocketRate=0;

//声音

publicAudioClipm_shootClip;

protectedAudioSourcem_audio;

//爆炸特效

m_audio=this.audio;

//纵向移动距离

floatmovev=0;

//水平移动距离

floatmoveh=0;

//按上键

if(Input.GetKey(KeyCode.UpArrow))

movev-=m_speed*Time.deltaTime;

//按下键

if(Input.GetKey(KeyCode.DownArrow))

movev+=m_speed*Time.deltaTime;

//按左键

if(Input.GetKey(KeyCode.LeftArrow))

moveh+=m_speed*Time.deltaTime;

//按右键

if(Input.GetKey(KeyCode.RightArrow))

moveh-=m_speed*Time.deltaTime;

//移动

this.m_transform.Translate(newVector3(moveh,0,movev));

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);

m_life-=1;

=0)

(6)Rocket子弹的源码:

MyGame/Rocket"

publicclassRocket:

//子弹飞行速度

publicfloatm_speed=10;

//生存时间

publicfloatm_liveTime=1;

//威力

publicfloatm_power=1.0f;

protectedTransformm_trasform;

m_trasform=this.transform;

m_liveTime-=Time.deltaTime;

if(m_liveTime<

m_trasform.Translate(newVector3(0,0,-m_speed*Time.deltaTime));

Enemy"

)!

=0)

(7)SuperEnemy源码:

MyGame/SuperEnemy"

publicclassSuperEnemy:

Enemy{

protectedfloatm_fireTimer=2;

protectedTransformm_player;

GameObjectobj=GameObject.FindGameObjectWithTag("

if(obj!

=null)

m_player=obj.transform;

protectedoverridevoidUpdateMove()

m_fireTimer-=Time.deltaTime;

if(m_fireTimer<

m_fireTimer=2;

if(m_player!

Vector3relativePos=m_transform.position-m_player.position;

Instantiate(m_rocket,m_transform.position,Quaternion.LookRotation(relativePos));

(8)TitleScreen的源码:

MyGame/TitleScreen"

publicclassTitleScreen:

//文字大小

GUI.skin.label.fontSize=48;

//UI中心对齐

//显示标题

GUI.Label(newRect(0,30,Screen.width,100),"

太空大战"

//开始游戏按钮

if(GUI.Button(newRect(Screen.width*0.5f-100,Screen.height*0.7f,200,30),"

开始游戏"

//开始读取下一关

Application.LoadLevel("

level1"

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 动物植物

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1