ImageVerifierCode 换一换
格式:DOCX , 页数:14 ,大小:17.35KB ,
资源ID:5899781      下载积分:12 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/5899781.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Unity3D太空大战.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Unity3D太空大战.docx

1、Unity3D太空大战Unity3D太空大战源码(1)Enemy的源码:using UnityEngine;using System.Collections;AddComponentMenu(MyGame/Enemy)public class Enemy : MonoBehaviour / 速度 public float m_speed = 1; / 生命 public float m_life = 10; / 旋转速度 protected float m_rotSpeed = 30; / 变向间隔时间 protected float m_timer = 1.5f; protected Tra

2、nsform m_transform; public Transform m_explosionFX; public int m_point = 10; / Use this for initialization void Start () m_transform = this.transform; / Update is called once per frame void Update () UpdateMove(); protected virtual void UpdateMove() m_timer -= Time.deltaTime; if (m_timer = 0) m_time

3、r = 3; /改变旋转方向 m_rotSpeed = -m_rotSpeed; / 旋转方向 m_transform.Rotate(Vector3.up, m_rotSpeed * Time.deltaTime, Space.World); / 前进 m_transform.Translate(new Vector3(0, 0, -m_speed * Time.deltaTime); void OnTriggerEnter(Collider other) if (other.tag.CompareTo(PlayerRocket) = 0) Rocket rocket = other.GetC

4、omponent(); if (rocket != null) m_life -= rocket.m_power; if (m_life = 0) GameManager.Instance.AddScore(m_point); Instantiate(m_explosionFX, m_transform.position, Quaternion.identity); Destroy(this.gameObject); else if (other.tag.CompareTo(Player) = 0) m_life = 0; Instantiate(m_explosionFX, m_transf

5、orm.position, Quaternion.identity); Destroy(this.gameObject); if (other.tag.CompareTo(bound) = 0) m_life = 0; Destroy(this.gameObject); (2)EnemyRocket的源码:using UnityEngine;using System.Collections;AddComponentMenu(MyGame/EnemyRocket)public class EnemyRocket : Rocket void OnTriggerEnter(Collider othe

6、r) if (other.tag.CompareTo(Player) != 0) return; Destroy(this.gameObject); (3)EnemySpawn敌人生成器:using UnityEngine;using System.Collections;AddComponentMenu(MyGame/EnemySpawn)public class EnemySpawn : MonoBehaviour / 敌人的Prefab public Transform m_enemy; / 生成敌人的时间间隔 protected float m_timer = 5; protected

7、 Transform m_transform; / Use this for initialization void Start () m_transform = this.transform; / Update is called once per frame void Update () m_timer -= Time.deltaTime; if (m_timer = 0) m_timer = Random.value * 15.0f; if (m_timer 5) m_timer = 5; Instantiate(m_enemy, m_transform.position, Quater

8、nion.identity); void OnDrawGizmos () Gizmos.DrawIcon (transform.position, item.png, true); (4)GameMannager图形界面:using UnityEngine;using System.Collections;AddComponentMenu(MyGame/GameManager)public class GameManager : MonoBehaviour public static GameManager Instance; /得分 public int m_score = 0; /纪录 p

9、ublic static int m_hiscore = 0; /主角 protected Player m_player; / 背景音乐 public AudioClip m_musicClip; / 声音源 protected AudioSource m_Audio; void Awake() Instance = this; / Use this for initialization void Start () m_Audio = this.audio; / 获取主角 GameObject obj = GameObject.FindGameObjectWithTag(Player); i

10、f (obj != null) m_player = obj.GetComponent(); / Update is called once per frame void Update () / 循环播放背景音乐 if (!m_Audio.isPlaying) m_Audio.clip = m_musicClip; m_Audio.Play(); / 暂停游戏 if (Time.timeScale 0 & Input.GetKeyDown(KeyCode.Escape) Time.timeScale = 0; void OnGUI() / 游戏暂停 if (Time.timeScale = 0

11、) / 继续游戏按钮 if (GUI.Button(new Rect(Screen.width * 0.5f - 50, Screen.height * 0.4f, 100, 30), 继续游戏) Time.timeScale = 1; / 退出游戏按钮 if (GUI.Button(new Rect(Screen.width * 0.5f - 50, Screen.height * 0.6f, 100, 30), 退出游戏) / 退出游戏 Application.Quit(); int life = 0; if (m_player != null) / 获得主角的生命值 life = (in

12、t)m_player.m_life; else / game over / 放大字体 GUI.skin.label.fontSize = 50; / 显示游戏失败 GUI.skin.label.alignment = TextAnchor.LowerCenter; GUI.Label(new Rect(0, Screen.height * 0.2f, Screen.width, 60), 游戏失败); GUI.skin.label.fontSize = 20; / 显示按钮 if (GUI.Button(new Rect(Screen.width * 0.5f - 50, Screen.hei

13、ght * 0.5f, 100, 30), 再试一次) / 读取当前关卡 Application.LoadLevel(Application.loadedLevelName); GUI.skin.label.fontSize = 15; / 显示主角生命 GUI.Label(new Rect(5, 5, 100, 30), 装甲 + life); / 显示最高分 GUI.skin.label.alignment = TextAnchor.LowerCenter; GUI.Label(new Rect(0, 5, Screen.width, 30), 纪录 + m_hiscore); / 显示当

14、前得分 GUI.Label(new Rect(0, 25, Screen.width, 30), 得分 + m_score); / 增加分数 public void AddScore( int point ) m_score += point; / 更新高分纪录 if (m_hiscore m_score) m_hiscore = m_score; (5)Player主飞船的源码:using UnityEngine;using System.Collections;AddComponentMenu(MyGame/Player)public class Player : MonoBehaviou

15、r / 速度 public float m_speed = 1; / 生命 public float m_life = 3; / 子弹prefab public Transform m_rocket; protected Transform m_transform; / 发射子弹频率 float m_rocketRate = 0; / 声音 public AudioClip m_shootClip; / 声音源 protected AudioSource m_audio; / 爆炸特效 public Transform m_explosionFX; / Use this for initial

16、ization void Start () m_transform = this.transform; m_audio = this.audio; / Update is called once per frame void Update () / 纵向移动距离 float movev=0; / 水平移动距离 float moveh=0; / 按上键 if ( Input.GetKey( KeyCode.UpArrow ) ) movev -= m_speed * Time.deltaTime; / 按下键 if ( Input.GetKey( KeyCode.DownArrow ) ) mo

17、vev += 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( new Vector3( moveh, 0, movev ) ); m_rocketRate -= Time.deltaTime; if

18、( 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 OnTriggerEnter(Collider other) if (other.tag.CompareTo(PlayerRocket) != 0) m_l

19、ife -= 1; if (m_life = 0) / 爆炸特效 Instantiate(m_explosionFX, m_transform.position, Quaternion.identity); Destroy(this.gameObject); (6)Rocket子弹的源码:using UnityEngine;using System.Collections;AddComponentMenu(MyGame/Rocket)public class Rocket : MonoBehaviour / 子弹飞行速度 public float m_speed = 10; / 生存时间 pu

20、blic float m_liveTime = 1; / 威力 public float m_power = 1.0f; protected Transform m_trasform; / Use this for initialization void Start () m_trasform = this.transform; / Update is called once per frame void Update () m_liveTime -= Time.deltaTime; if (m_liveTime = 0) Destroy(this.gameObject); m_trasfor

21、m.Translate( new Vector3( 0, 0, -m_speed * Time.deltaTime ) ); void OnTriggerEnter(Collider other) if (other.tag.CompareTo(Enemy)!=0) return; Destroy(this.gameObject); (7)SuperEnemy源码:using UnityEngine;using System.Collections;AddComponentMenu(MyGame/SuperEnemy)public class SuperEnemy : Enemy public

22、 Transform m_rocket; protected float m_fireTimer = 2; protected Transform m_player; void Awake() GameObject obj=GameObject.FindGameObjectWithTag(Player); if ( obj!=null ) m_player=obj.transform; protected override void UpdateMove() m_fireTimer -= Time.deltaTime; if (m_fireTimer = 0) m_fireTimer = 2;

23、 if ( m_player!=null ) Vector3 relativePos = m_transform.position-m_player.position; Instantiate( m_rocket, m_transform.position, Quaternion.LookRotation(relativePos) ); / 前进 m_transform.Translate(new Vector3(0, 0, -m_speed * Time.deltaTime); (8)TitleScreen的源码:using UnityEngine;using System.Collecti

24、ons;AddComponentMenu(MyGame/TitleScreen)public class TitleScreen : MonoBehaviour void OnGUI() / 文字大小 GUI.skin.label.fontSize = 48; / UI中心对齐 GUI.skin.label.alignment = TextAnchor.LowerCenter; / 显示标题 GUI.Label(new Rect(0, 30, Screen.width, 100), 太空大战); / 开始游戏按钮 if (GUI.Button(new Rect(Screen.width * 0.5f - 100, Screen.height * 0.7f, 200, 30), 开始游戏) / 开始读取下一关 Application.LoadLevel(level1);

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

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