Fixed bug with box spawns. Boxes and containers get random colour on start. Optimised code/Removed script

Added explanation of comment symbols/colours
This commit is contained in:
Santi 2024-06-13 01:52:43 +01:00
parent 3111305a83
commit c39ff0c263
12 changed files with 896 additions and 2061 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,19 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoxSpawns : MonoBehaviour
{
//*Start is called before the first frame update
void Start()
{
//*Randomly spawn boxes when the game starts
gameObject.transform.position = new Vector3(Random.Range(10, -10), 15, Random.Range(-10, 10));
}
//*Update is called once per frame
void Update()
{
}
}

View File

@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//* 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;
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Container")
{
currentContainer = other.gameObject;
//* If the box is not the same colour as the container, teleport the box
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));
}
else
{
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));
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: c4117eaed8044c04fa8e28e453955ca6 guid: b82d7abf31c7ee246af2125333411a70
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -1,55 +1,39 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Unity.VisualScripting; using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
//* General Comments or Finished Tasks
//TODO Tasks left to be done for game
//! Bugs or Issues
//? Questions or Suggestions
//* Cubes need to randomly fall from the sky within the play area at the start of the game, //* 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. //* 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 //* 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 //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 //! Somtimes boxes get thrown further than other times. Boxes also sometimes get thrown into random directions.
public class Colours : MonoBehaviour public class Colours : MonoBehaviour
{ {
public bool done = false; public GameObject Box;
public GameObject[] boxes; public GameObject[] containers;
public int waitTime = 3; public List<Material> materials = new List<Material>();
private bool tp = false; private GameObject currentBox;
//*Start is called before the first frame update private int num;
//* Start is called before the first frame update
void Start() void Start()
{ {
//* Instantiate 8 containers with random colours at the start of the game
} for (int i = 0; i < containers.Length; i++)
//*Update is called once per frame
void Update()
{ {
currentBox = Instantiate(Box, new Vector3(Random.Range(10, -10), 15, Random.Range(-10, 10)), Quaternion.identity);
num = Random.Range(0, materials.Count);
currentBox.GetComponent<Renderer>().material = materials[num];
containers[i].GetComponent<Renderer>().material = materials[num];
materials.RemoveAt(num);
} }
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));
} }
} }

View File

@ -4,6 +4,11 @@ using System.Dynamic;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
//* General Comments or Finished Tasks
//TODO Tasks left to be done for game
//! Bugs or Issues
//? Questions or Suggestions
public class Hamor : MonoBehaviour public class Hamor : MonoBehaviour
{ {
public Animator hamorAnimator; public Animator hamorAnimator;
@ -13,18 +18,18 @@ public class Hamor : MonoBehaviour
public TextMeshProUGUI scoreText; public TextMeshProUGUI scoreText;
public int score = 0; public int score = 0;
public Moles_IsHit moles; public Moles_IsHit moles;
//*Start is called before the first frame update //* Start is called before the first frame update
void Start() void Start()
{ {
} }
//*Update is called once per frame //* Update is called once per frame
void Update() void Update()
{ {
if(Input.GetMouseButtonDown(0)) if(Input.GetMouseButtonDown(0))
{ {
hamorAnimator.SetTrigger("Bonk"); //*Play the bonk animation hamorAnimator.SetTrigger("Bonk"); //* Play the bonk animation
} }
} }
@ -39,7 +44,7 @@ public class Hamor : MonoBehaviour
{ {
if(other.tag != "Player") if(other.tag != "Player")
{ {
//*Play the bonk particles //* Play the bonk particles
var parLocation = Instantiate(bonkParticles, contact.transform.position, Quaternion.identity); var parLocation = Instantiate(bonkParticles, contact.transform.position, Quaternion.identity);
Destroy(parLocation, 1); Destroy(parLocation, 1);
particles = true; particles = true;
@ -49,10 +54,10 @@ public class Hamor : MonoBehaviour
if(other.gameObject.tag == "Mole") if(other.gameObject.tag == "Mole")
{ {
//*Get the Moles_IsHit script from the mole //* Get the Moles_IsHit script from the mole
moles = other.gameObject.GetComponent<Moles_IsHit>(); moles = other.gameObject.GetComponent<Moles_IsHit>();
//*If the mole has not been hit, increase the score and change bool //* If the mole has not been hit, increase the score and change bool
if(moles.IsHit == false) if(moles.IsHit == false)
{ {
score += 1; score += 1;

View File

@ -2,6 +2,11 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
//* General Comments or Finished Tasks
//TODO Tasks left to be done for game
//! Bugs or Issues
//? Questions or Suggestions
public class MeshCombiner : MonoBehaviour public class MeshCombiner : MonoBehaviour
{ {
[SerializeField] private List<MeshFilter> sourceMeshFilters; [SerializeField] private List<MeshFilter> sourceMeshFilters;

View File

@ -4,6 +4,11 @@ using JetBrains.Annotations;
using Unity.VisualScripting; using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
//* General Comments or Finished Tasks
//TODO Tasks left to be done for game
//! Bugs or Issues
//? Questions or Suggestions
//TODO Moles need to change textures when hit to show they have been hit - need textures for this //TODO Moles need to change textures when hit to show they have been hit - need textures for this
//* As the time goes on, moles appear and disappear faster //* As the time goes on, moles appear and disappear faster
@ -15,13 +20,13 @@ public class Moles : MonoBehaviour
public float lifeTime = 5f; public float lifeTime = 5f;
public bool moleCanAppear = false; public bool moleCanAppear = false;
public int randomHole, randomHole2, randomHole3; public int randomHole, randomHole2, randomHole3;
// Start is called before the first frame update //* Start is called before the first frame update
void Start() void Start()
{ {
moleCanAppear = true; moleCanAppear = true;
} }
// Update is called once per frame //* Update is called once per frame
void Update() void Update()
{ {
if(moleCanAppear) if(moleCanAppear)
@ -47,7 +52,7 @@ public class Moles : MonoBehaviour
void holeSelection(int randomHole) void holeSelection(int randomHole)
{ {
// Prevent the same hole from being selected twice //* Prevent the same hole from being selected twice
switch (randomHole) switch (randomHole)
{ {
case 1: case 1:

View File

@ -2,16 +2,21 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
//* General Comments or Finished Tasks
//TODO Tasks left to be done for game
//! Bugs or Issues
//? Questions or Suggestions
public class Moles_IsHit : MonoBehaviour public class Moles_IsHit : MonoBehaviour
{ {
public bool IsHit; public bool IsHit;
//*Start is called before the first frame update //* Start is called before the first frame update
void Start() void Start()
{ {
IsHit = false; //*Mole starts as not being hit IsHit = false; //* Mole starts as not being hit
} }
//*Update is called once per frame //* Update is called once per frame
void Update() void Update()
{ {

View File

@ -6,6 +6,11 @@ using UnityEngine;
using UnityEngine.Animations; using UnityEngine.Animations;
using UnityEngine.UIElements; using UnityEngine.UIElements;
//* General Comments or Finished Tasks
//TODO Tasks left to be done for game
//! Bugs or Issues
//? Questions or Suggestions
public class PickUpObject : MonoBehaviour public class PickUpObject : MonoBehaviour
{ {
public GameObject carryPosition; // blank object, position declares where the object will be teleported to/carried public GameObject carryPosition; // blank object, position declares where the object will be teleported to/carried

View File

@ -3,6 +3,11 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using TMPro; using TMPro;
//* General Comments or Finished Tasks
//TODO Tasks left to be done for game
//! Bugs or Issues
//? Questions or Suggestions
public class Timer : MonoBehaviour public class Timer : MonoBehaviour
{ {
public float timeRemaining; public float timeRemaining;

View File

@ -7,6 +7,7 @@ TagManager:
- Floor - Floor
- PickupObject - PickupObject
- Mole - Mole
- Container
layers: layers:
- Default - Default
- TransparentFX - TransparentFX