Mini-Games-Game/Assets/Scripts/BoxTeleport.cs

51 lines
1.4 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2024-06-24 23:53:55 +01:00
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;
2024-06-24 23:53:55 +01:00
public TextMeshProUGUI scoreText;
private int score;
2024-06-24 23:53:55 +01:00
void Start()
{
scoreText.text = "Score: 0";
}
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Container")
{
currentContainer = other.gameObject;
2024-06-24 23:53:55 +01:00
//* If the box is not the same colour as the container, teleport the box after a few seconds
if(currentContainer.gameObject.GetComponentInParent<Renderer>().material.name == gameObject.GetComponent<Renderer>().material.name)
{
gameObject.transform.position = new Vector3(Random.Range(10, -10), 15, Random.Range(-10, 10));
2024-06-24 23:53:55 +01:00
score =+ 1;
scoreText.text = "Score: " + score;
}
else
{
2024-06-24 23:53:55 +01:00
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));
}
}