using System.Collections; using System.Collections.Generic; using UnityEngine; //* General Comments or Finished Tasks //TODO Tasks left to be done for game //! Bugs or Issues //? Questions or Suggestions public class BoxTeleport : MonoBehaviour { private GameObject currentContainer; public int waitTime = 3; private void OnTriggerEnter(Collider other) { if(other.gameObject.tag == "Container") { currentContainer = other.gameObject; //* If the box is not the same colour as the container, teleport the box if(currentContainer.gameObject.GetComponentInParent().material.name == gameObject.GetComponent().material.name) { gameObject.transform.position = new Vector3(Random.Range(10, -10), 15, Random.Range(-10, 10)); } else { StartCoroutine(BoxSpawn()); } } } //* Teleport the box to a random location in the air IEnumerator BoxSpawn() { yield return new WaitForSeconds(waitTime); gameObject.transform.position = new Vector3(Random.Range(10, -10), 15, Random.Range(-10, 10)); } }