Open-sourced some code

This commit is contained in:
2019-03-08 09:54:14 +11:00
commit 645272872c
142 changed files with 3028 additions and 0 deletions
@@ -0,0 +1,36 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ProximitySpawner : MonoBehaviour {
//public access members
public GameObject prefab;
public string targetTag;
public float minDistance = 4f;
public float maxDistance = 10f;
public bool destroyIfTooFar = false;
//private members
Transform targetTransform;
GameObject spawnedObject;
void Start() {
targetTransform = GameObject.FindWithTag(targetTag).transform;
}
void Update() {
//get the distance
float distance = Vector3.Distance(transform.position, targetTransform.position);
//destroy if the player is too far away
if (destroyIfTooFar && distance > maxDistance) {
Destroy(spawnedObject);
return; //skip out on the next check
}
//check the distance, check the spawned object
if (distance > minDistance && distance < maxDistance && spawnedObject == null) {
spawnedObject = Instantiate(prefab);
}
}
}