using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; //* 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; public TextMeshProUGUI scoreText; private int score; void Start() { scoreText.text = "Score: 0"; } 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 after a few seconds if(currentContainer.gameObject.GetComponentInParent().material.name == gameObject.GetComponent().material.name) { gameObject.transform.position = new Vector3(Random.Range(10, -10), 15, Random.Range(-10, 10)); score =+ 1; scoreText.text = "Score: " + score; } 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)); } }