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

56 lines
1.7 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Unity.VisualScripting;
using UnityEngine;
//* Cubes need to randomly fall from the sky within the play area at the start of the game,
//TODO when the player drops it in the right container teleport cube into random location in the air.
//TODO Containers need to be randomly allocated a colour at the start of the game
//TODO As the timer goes down, the containers have a chance to switch renders/colours
//! When cube is dropped into the wrong container, the cube is teleported several times - Needs fix
public class Colours : MonoBehaviour
{
public bool done = false;
public GameObject[] boxes;
public int waitTime = 3;
private bool tp = false;
//*Start is called before the first frame update
void Start()
{
}
//*Update is called once per frame
void Update()
{
}
private void OnTriggerEnter(Collider other)
{
//*If the box is the same colour as the container, set done to true
if(other.gameObject.GetComponent<Renderer>().material.name == gameObject.GetComponentInParent<Renderer>().material.name && !done)
{
done = true;
}
else
{
//*If the box is not the same colour as the container, teleport the box
if(!tp)
{
tp = true;
StartCoroutine(BoxSpawn(other));
}
}
}
//*Teleport the box to a random location in the air
IEnumerator BoxSpawn(Collider other)
{
yield return new WaitForSeconds(waitTime);
other.transform.position = new Vector3(Random.Range(10, -10), 15, Random.Range(-10, 10));
}
}