我正在开发一款关于僵尸生存的游戏,在游戏中,我有一些游戏对象作为僵尸生成点。当这些生成点不在摄像机视野内时,我想要生成僵尸。那么,如何检查生成点是否在摄像机视野之外以便生成它们呢?
下面是我的敌人生成脚本。
敌人生成
下面是我的敌人生成脚本。
敌人生成
public class EnemyManager : MonoBehaviour
{
PlayerHealth playerHealth; // Reference to the player's heatlh.
public GameObject enemy; // The enemy prefab to be spawned.
public float spawnTime = 3f; // How long between each spawn.
public Transform[] spawnPoints; // An array of the spawn points this enemy can spawn from.
void Start ()
{
// Call the Spawn function after a delay of the spawnTime and then continue to call after the same amount of time.
playerHealth = GameObject.FindWithTag("Player").GetComponent<PlayerHealth>();
InvokeRepeating ("Spawn", spawnTime, spawnTime);
}
void Spawn ()
{
// If the player has no health left...
if(playerHealth.currentHealth <= 0f)
{
// ... exit the function.
return;
}
// Find a random index between zero and one less than the number of spawn points.
int spawnPointIndex = UnityEngine.Random.Range (0, spawnPoints.Length);
// Create an instance of the enemy prefab at the randomly selected spawn point's position and rotation.
Instantiate (enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
}
}