本文主要是介绍[初学Unity]Space Shooter Tutorial Extension,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Part 4 Extending Space Shooter
EXTENDING SPACE SHOOTER: ENEMIES, MORE HAZARDS, SCROLLING BG…
We will be covering how to add enemies with very basic manoeuvring and shooting, additional hazards of different types and scrolling the background.
通过复制Asteroid GameObject和替换子GameObject,添加另外两种类型的陨石,更改他们的Collider以适应各自的形状。
Update Scripts : GameController.cs
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;public class GameController : MonoBehaviour
{public GameObject[] hazards; // 数组,用来存放 各种小行星public Vector3 spawnValues; // 通过Inspector来设置spawnValues,继而在SpawnWaves中设置spawnPositionpublic int hazardCount; // 每一波的小行星数量public float spawnWait; // 相邻两个小行星的生成时间间隔public float startWait; // a short pause after the game starts for the player to get readypublic float waveWait; // 相邻两波之间的时间间隔public GUIText scoreText; // We will feed information to these labels as the game progresses.public GUIText restartText;public GUIText gameOverText;private bool gameOver;private bool restart;private int score;void Start(){gameOver = false;restart = false;gameOverText.text = "";restartText.text = "";score = 0; // starting valueUpdateScore();StartCoroutine(SpawnWaves());}void Update(){if(restart){if(Input.GetKeyDown(KeyCode.R)){// Application.LoadLevel(Application.loadedLevel); // restart the gameSceneManager.LoadScene("_Scenes/main"); // 重新加载这个 Scene Loads the scene by its name or index in Build Settings.}}}IEnumerator SpawnWaves(){yield return new WaitForSeconds(startWait);while(true){for (int i = 0; i < hazardCount; i++){GameObject hazard = hazards[Random.Range(0, hazards.Length)]; // 随机从数组 hazards 中选取一个元素 hazard,NICEVector3 spawnPosition = new Vector3(Random.Range(-spa
这篇关于[初学Unity]Space Shooter Tutorial Extension的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!