This document provides instructions for setting up a space shooter game in Unity. It describes creating a new Unity project, importing asset packages, configuring scenes and game objects, adding scripts, and testing gameplay functionality. Key steps include setting up the player ship game object with rigidbody and collider components, configuring lighting and cameras, adding a background, and writing scripts to control ship movement and fire projectiles. The goal is to implement the basic mechanics of a space shooter game in Unity according to an online tutorial.
22. shapethefuture
Bolt物件加上Mover程式腳本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Mover : MonoBehaviour {
public float speed;
// Use this for initialization
void Start () {
GetComponent<Rigidbody>().velocity = transform.forward * speed;
}
}
建立玩家戰機子彈 3/4
22 Wu, ShyiShiou Dept. of E.E., NKUT
40. shapethefuture
編輯GameController程式腳本
public class GameController : MonoBehaviour {
public GameObject hazard;
public Vector3 spawnValues;
public int hazardCount;
public float spawnWait;
public float startWait;
public float waveWait;
void Start ()
{
StartCoroutine (SpawnWaves ());
}
設定隕石群 1/4
40 Wu, ShyiShiou Dept. of E.E., NKUT
41. shapethefuture
IEnumerator SpawnWaves ()
{
yield return new WaitForSeconds (startWait);
while (true)
{
for (int i = 0; i < hazardCount; i++)
{
Vector3 spawnPosition = new Vector3 (
Random.Range (-spawnValues.x, spawnValues.x),
spawnValues.y,
spawnValues.z);
Quaternion spawnRotation = Quaternion.identity;
Instantiate (hazard, spawnPosition, spawnRotation);
yield return new WaitForSeconds (spawnWait);
}
yield return new WaitForSeconds (waveWait);
}
}
}
設定隕石群 2/4
41 Wu, ShyiShiou Dept. of E.E., NKUT
42. shapethefuture
執行測試,隕石會定時自動生成,但是...
擊破隕石時生成的爆破效果物件不會自動銷毀
建立DestroyByTime程式腳本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyByTime : MonoBehaviour {
public float lifetime;
void Start ()
{
Destroy (gameObject, lifetime);
}
}
設定隕石群 3/4
42 Wu, ShyiShiou Dept. of E.E., NKUT