64 lines
2.1 KiB
C#
64 lines
2.1 KiB
C#
|
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
|
||
|
|
||
|
//TODO Create Catch Game:
|
||
|
//* Objects constantly and randomly spawn in the air
|
||
|
//* Player must catch (just touch) the objects before they hit the ground
|
||
|
//* The player has a score that increases by 1 for each object caught
|
||
|
//* The player has a timer that counts down from 60 seconds
|
||
|
//* The game ends when the timer reaches 0
|
||
|
//TODO Some objects are worth more points than others and fall faster
|
||
|
//TODO Some objects are bombs and will decrease the player's score if in radius
|
||
|
//TODO Objects smash on the ground if not caught, create particles
|
||
|
|
||
|
public class BoxTP_Catch : MonoBehaviour
|
||
|
{
|
||
|
public GameObject[] objects;
|
||
|
public TextMeshProUGUI scoreText;
|
||
|
public float defaultSpeed = 1.5f;
|
||
|
public float timerSpeed;
|
||
|
public Timer timer;
|
||
|
public bool canSpawn = true;
|
||
|
void Start()
|
||
|
{
|
||
|
scoreText.text = "Score: 0";
|
||
|
}
|
||
|
|
||
|
void FixedUpdate() {
|
||
|
|
||
|
timerSpeed = defaultSpeed * (timer.timeRemaining/60);
|
||
|
|
||
|
//spawn object a random object from the list every few seconds, randomly on the x and z axis
|
||
|
//if the object is not caught, destroy it
|
||
|
//if the object is caught, increase score by 1
|
||
|
if(timer.timeRemaining-1 > 0)
|
||
|
{
|
||
|
if (canSpawn) {
|
||
|
GameObject currentObject = Instantiate(objects[Random.Range(0, objects.Length)], new Vector3(Random.Range(5f, -5f), 15,- Random.Range(-5f, 5f)), Quaternion.identity);
|
||
|
currentObject.GetComponent<Rigidbody>().useGravity = true;
|
||
|
canSpawn = false;
|
||
|
StartCoroutine(SpawnTimer());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
IEnumerator SpawnTimer() {
|
||
|
yield return new WaitForSeconds(timerSpeed);
|
||
|
canSpawn = true;
|
||
|
}
|
||
|
|
||
|
private void OnTriggerEnter(Collider other) {
|
||
|
if(other.gameObject.tag == "PickupObject" || other.gameObject.tag == "Bomb" || other.gameObject.tag == "SpecialObject")
|
||
|
{
|
||
|
Destroy(other.gameObject);
|
||
|
}
|
||
|
}
|
||
|
}
|