Mini-Games-Game/Assets/Scripts/Colours.cs
Santi 3111305a83 WackAMole: Moles only give one point per, a timer has been added, comments
Timer: Created a universal timer

Colours: Improved Comments, cubes now randomly appear on start. When a cube is in a container it gets randomly teleported back
2024-06-07 14:37:52 +01:00

56 lines
1.7 KiB
C#

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));
}
}