【发布时间】:2016-03-11 23:05:09
【问题描述】:
我在 Unity (C#) 上编写简单的游戏
我有玩家,想制作毁灭者,会摧毁玩家。
我创建了驱逐舰的预制件。接下来,我创建 Quad。
我有生成脚本:
using UnityEngine;
using System.Collections;
public class SpawnScript : MonoBehaviour {
public GameObject[] obj;
public float spawnMin = 1f;
public float spawnMax = 2f;
// Use this for initialization
void Start () {
Spawn();
}
void Spawn()
{
Instantiate(obj[Random.Range(0, obj.GetLength(0))], transform.position, Quaternion.identity);
Invoke("Spawn", Random.Range(spawnMin, spawnMax));
}
}
我也写了 DestroyerScript:
using UnityEngine;
using System.Collections;
public class DestroyerScript : MonoBehaviour {
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
Application.LoadLevel(1);
return;
}
if (other.gameObject.transform.parent)
{
Destroy(other.gameObject.transform.parent.gameObject);
}
else
{
Destroy(other.gameObject);
}
}
}
我的驱逐舰正在生成,但是当玩家得到它时,我没有游戏结束屏幕。
【问题讨论】: