2024-04-30 19:45:02 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2024-06-07 14:37:52 +01:00
|
|
|
using System.Runtime.Serialization;
|
2024-04-30 19:45:02 +01:00
|
|
|
using Unity.VisualScripting;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2024-06-07 14:37:52 +01:00
|
|
|
//* 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
|
2024-04-30 19:45:02 +01:00
|
|
|
public class Colours : MonoBehaviour
|
|
|
|
{
|
|
|
|
public bool done = false;
|
2024-06-07 14:37:52 +01:00
|
|
|
public GameObject[] boxes;
|
|
|
|
public int waitTime = 3;
|
|
|
|
private bool tp = false;
|
|
|
|
//*Start is called before the first frame update
|
2024-04-30 19:45:02 +01:00
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-06-07 14:37:52 +01:00
|
|
|
//*Update is called once per frame
|
2024-04-30 19:45:02 +01:00
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
|
{
|
2024-06-07 14:37:52 +01:00
|
|
|
//*If the box is the same colour as the container, set done to true
|
2024-04-30 19:45:02 +01:00
|
|
|
if(other.gameObject.GetComponent<Renderer>().material.name == gameObject.GetComponentInParent<Renderer>().material.name && !done)
|
|
|
|
{
|
|
|
|
done = true;
|
|
|
|
}
|
2024-06-07 14:37:52 +01:00
|
|
|
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));
|
2024-04-30 19:45:02 +01:00
|
|
|
}
|
|
|
|
}
|