lib-unity-presentation-Assets-Scripts-Spawner.cs / cs
using UnityEngine; using System.Collections; public class Spawner : MonoBehaviour { public Transform trans; public float interval; private Transform player; public float randomScale = 1; public bool doAlways = false; void Awake() { player = GameObject.FindGameObjectWithTag("Player").transform; InvokeRepeating("Spawn", interval, interval); } void Spawn () { //Only spawn if player is close by if(doAlways || Vector3.Distance(transform.position, player.position)<=50) Instantiate(trans, transform.position+Random.insideUnitSphere, transform.rotation); } }
(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.