topical media & game development
lib-unity-tutorial-m2h-2-Assets-Game-1-Catch-eggs-Scripts-SpawnerScript.cs / cs
using UnityEngine;
using System.Collections;
public class SpawnerScript : MonoBehaviour {
public Transform eggPrefab;
private float nextEggTime = 0.0f;
private float spawnRate = 1.5f;
void Update () {
if (nextEggTime < Time.time)
{
SpawnEgg();
nextEggTime = Time.time + spawnRate;
//Speed up the spawnrate for the next egg
spawnRate *= 0.98f;
spawnRate = Mathf.Clamp(spawnRate, 0.3f, 99f);
}
}
void SpawnEgg()
{
float addXPos = Random.Range(-1.6f, 1.6f);
Vector3 spawnPos = transform.position + new Vector3(addXPos,0,0);
Instantiate(eggPrefab, spawnPos, Quaternion.identity);
}
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.