Game Development Reference
In-Depth Information
4. Go ahead and give it a nice spinning animation by rotating the Z axis from
0 to 356 .
5. Once you're happy with it, create a new script called EnemyRespawner
and code it up as shown in the following code snippet:
using UnityEngine;
using System.Collections;
public class EnemyRespawner : MonoBehaviour
{
public GameObject spawnEnemy = null;
float respawnTime = 0.0f;
void OnEnable()
{
EnemyControllerScript.enemyDied += scheduleRespawn;
}
void OnDisable()
{
EnemyControllerScript.enemyDied -= scheduleRespawn;
}
// Note: Even though we don't need the enemyScore, we still
// need to accept it because the event passes it
void scheduleRespawn(int enemyScore)
{
// Randomly decide if we will respawn or not
if(Random.Range(0,10) < 5)
return;
respawnTime = Time.time + 4.0f;
}
void Update()
{
if(respawnTime > 0.0f)
{
if(respawnTime < Time.time)
{
 
Search WWH ::




Custom Search