用3dunity制作飛機(jī)射擊游戲_第1頁
用3dunity制作飛機(jī)射擊游戲_第2頁
用3dunity制作飛機(jī)射擊游戲_第3頁
用3dunity制作飛機(jī)射擊游戲_第4頁
用3dunity制作飛機(jī)射擊游戲_第5頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、操作系統(tǒng)實(shí)驗(yàn)游戲:打飛機(jī)實(shí)驗(yàn)小組名單:竇曉磊一、 設(shè)計(jì)主要完成的任務(wù)解決的主要問題 設(shè)計(jì)一個(gè)打飛機(jī)游戲能夠?qū)崿F(xiàn)基本的游戲體驗(yàn)二、 解決的主要問題解決飛機(jī)的控制問題。解決子彈與飛機(jī)的碰撞問題。解決敵方飛機(jī)的刷新問題三、 設(shè)計(jì)的基本概念利用unity3d的一些函數(shù)來構(gòu)建腳本,將腳本附加給原型使其可以接受控制。四、 總體設(shè)計(jì):實(shí)現(xiàn)的方法和主要技術(shù)路線使用unity3d游戲制作軟件進(jìn)行游戲制作,將網(wǎng)上找到的材料原型增加屬性以及添加腳本從而使游戲能夠運(yùn)行。建立Player.cs、Enemy.cs、Bullet.cs、Spaceship.cs、BackGround.cs、DestroyArea.cs、Em

2、itter.cs、Explosion.cs、Manager.cs、Score.cs腳本來建立與模型之間的聯(lián)系,起到控制飛機(jī),子彈發(fā)射,子彈與飛機(jī)之間碰撞后的消失,飛機(jī)消失的爆炸動(dòng)畫,飛機(jī)的飛行區(qū)域,背景圖案及音樂的設(shè)置,敵方飛機(jī)的出場(chǎng)以及得分。五、 詳細(xì)設(shè)計(jì):使用的主要控件、函數(shù)(1) 將從網(wǎng)上下載的飛機(jī)資源圖片剪裁并制作成動(dòng)畫,己方飛機(jī)飛行動(dòng)畫,敵方飛機(jī)飛行動(dòng)畫,兩方子彈。(2) 增添腳本Player.cs:用來控制飛船增添控制方法,速度,飛行區(qū)域,物體銷毀。public class player : MonoBehaviour /Spaceship ComponentSpaceship s

3、paceship;/ Use this for initializationIEnumerator Start () spaceship = GetComponent<Spaceship> ();/持續(xù)發(fā)射子彈while (true) spaceship.Shot (transform);/播放音效GetComponent<AudioSource>().Play();yield return new WaitForSeconds (spaceship.shotDelay);/間隔時(shí)間/ Update is called once per framevoid Update

4、 () /Right,Left/移動(dòng)float x = Input.GetAxisRaw ("Horizontal");/Up,Downfloat y = Input.GetAxisRaw ("Vertical");Vector2 direction = new Vector2 (x, y).normalized;spaceship.Move (direction);Clamp ();void Clamp()/得到視口坐標(biāo)0,0的世界坐標(biāo)Vector2 min = Camera.main.ViewportToWorldPoint (new Vector2

5、 (0, 0);/得到視口坐標(biāo)1,1的世界坐標(biāo)Vector2 max = Camera.main.ViewportToWorldPoint (new Vector2 (1, 1);/得到player的世界坐標(biāo)Vector2 pos = transform.position;/坐標(biāo)位置校正pos.x = Mathf.Clamp (pos.x, min.x+0.24f, max.x-0.24f);pos.y = Mathf.Clamp (pos.y, min.y+0.32f, max.y-0.32f);transform.position = pos;/Called at the moment c

6、ollision happensvoid OnTriggerEnter2D(Collider2D c)/得到碰撞物對(duì)象的LayerNamestring layerName=LayerMask.LayerToName(c.gameObject.layer);if (layerName = "Bullet(enemy)") /Delete the bulletDestroy (c.gameObject);if (layerName = "Bullet(enemy)" | layerName = "Enemy") FindObjectOfT

7、ype<Score>().Save();/Delete the playerDestroy (this.gameObject);/Explodespaceship.Explosion ();FindObjectOfType<Manager> ().GameOver ();Enemy.cs:用來控制敵方飛機(jī)的血量、物理碰撞,銷毀。public class Enemy : MonoBehaviour public int Hp = 1; public int point = 100;Spaceship spaceship;public bool canShot=true;/

8、 Use this for initializationIEnumerator Start () spaceship = GetComponent<Spaceship> ();spaceship.Move (transform.up * -1);while (true) for (int i = 0; i < transform.childCount; i+) Transform shotPosition = transform.GetChild (i);if(canShot)spaceship.Shot (shotPosition);yield return new Wai

9、tForSeconds (spaceship.shotDelay);/ Update is called once per framevoid Update () /Called at the moment collision happensvoid OnTriggerEnter2D(Collider2D c)/得到碰撞物對(duì)象的LayerNamestring layerName=LayerMask.LayerToName(c.gameObject.layer);if (layerName != "Bullet(player)")return; /Delete the bul

10、let Destroy(c.gameObject); Transform PlayerBulletTransform = c.transform.parent;Bullet bullet = PlayerBulletTransform.GetComponent<Bullet> ();Hp = Hp - bullet.power;if (Hp <= 0) FindObjectOfType<Score>().AddPoint(point);/Delete the playerDestroy (this.gameObject);/Explodespaceship.Exp

11、losion (); else spaceship.GetAnimator().SetTrigger("damage"); Spaceship:存儲(chǔ)所有飛船的共同屬性移動(dòng)速度,子彈延遲時(shí)間,移動(dòng),子彈等。RequireComponent(typeof(Rigidbody2D)/提示加入組件public class Spaceship : MonoBehaviour /移動(dòng)速度public float speed;/子彈延遲時(shí)間public float shotDelay;/子彈的prefabpublic GameObject bullet;/爆炸的prefabpublic

12、GameObject explosion; private Animator animator;/ Use this for initializationvoid Start () animator = GetComponent<Animator>();/ Update is called once per framevoid Update () public Animator GetAnimator() return animator; /生成子彈public void Shot(Transform origin)Instantiate (bullet, origin.posit

13、ion, origin.rotation);/移動(dòng)public void Move(Vector2 direction)GetComponent<Rigidbody2D>().velocity = direction * speed;/爆炸public void Explosion()Instantiate(explosion,transform.position,transform.rotation);Explosion.cs:控制飛船的爆炸特效。public class Explosion : MonoBehaviour void OnAnimationFinish()Dest

14、roy (gameObject);Bullet.cs:控制子彈的速度以及子彈的銷毀。Use this for initializationvoid Start () GetComponent<Rigidbody2D>().velocity = transform.up.normalized * speed;Destroy (gameObject, lifetime);BackGround.cs:控制背景圖片public class BackGround : MonoBehaviour /文理偏移速度public float speed=0.1f;/ Use this for ini

15、tializationvoid Start () / Update is called once per framevoid Update () /循環(huán)取得0-1之間的一個(gè)遞增的值float y = Mathf.Repeat (Time.time * speed, 1);/根據(jù)上面的遞增值生成一個(gè)Vector2對(duì)象Vector2 offset = new Vector2 (0, y);/這是物體的文理偏移GetComponent<Renderer>().sharedMaterial.SetTextureOffset("_MainTex",offset);Dest

16、royArea.cs:提供銷毀區(qū)域,銷毀超過圖景的子彈和敵軍飛機(jī)public class DestroyArea : MonoBehaviour void OnTriggerExit2D(Collider2D c)Destroy (c.gameObject);Emitter.cs:控制敵方飛機(jī)出現(xiàn)的波次以及出現(xiàn)方法public class Emitter : MonoBehaviour /保存Wave的Prefabspublic GameObject waves;/當(dāng)前的Waveprivate int currentWave;private Manager manager;/ Use this

17、 for initialization IEnumerator Start() if (waves.Length = 0) yield break; manager = FindObjectOfType<Manager>(); while (true) / 創(chuàng)建Wave GameObject wave = (GameObject)Instantiate(wavescurrentWave, transform.position, Quaternion.identity); / wave.transform.parent = transform; while (wave.transfo

18、rm.childCount != 0) yield return new WaitForEndOfFrame(); /刪除Wave Destroy(wave); if (waves.Length <= +currentWave) currentWave = 0; / Update is called once per framevoid Update () Manager.cs:控制提示語句的出現(xiàn)以及消失,開始游戲的按鍵設(shè)置等public class Manager : MonoBehaviour / Player Prefabpublic GameObject player;publi

19、c GameObject title;/ Use this for initializationvoid Start () title = GameObject.Find("Title");/ Update is called once per framevoid Update () if( IsPlaying() = false && Input.GetKeyDown(KeyCode.X) )GameStart();public void GameStart()title.SetActive(false);Instantiate(player, playe

20、r.transform.position, player.transform.rotation);public bool IsPlaying()return title.activeSelf = false;public void GameOver()title.SetActive(true);Score.cs:控制計(jì)數(shù)系統(tǒng),提供一個(gè)最高紀(jì)錄分?jǐn)?shù)以及本次游戲分?jǐn)?shù)public class Score : MonoBehaviour public GUIText hightScoreGUIText; public GUIText currentScoreGUIText; private int c

21、urrScore; private int hightScore; private string highScoreKey = "highScore"/ Use this for initializationvoid Start () Init();/ Update is called once per framevoid Update () if (currScore > hightScore) hightScore = currScore; currentScoreGUIText.text = "Your Score :"+currScore.ToString(); hightScoreGUIText.text = "HightScore: " + hightScore.ToString

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論