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