Updated game over state so all unnecessary objects get destroyed or disabled and all moveable items are non-clickable and fixed bug that reset timer after it passed 60 seconds

This commit is contained in:
Gregory Campbell
2020-06-07 13:12:56 -04:00
parent 0002b239fc
commit 8ca92ec70e
+36 -15
View File
@@ -32,23 +32,17 @@ public class GameScript : MonoBehaviour
{ {
clickDown = true; clickDown = true;
} }
timer += Time.deltaTime;
float seconds = timeLimit - (timer % 60);
//Debug.Log((int)seconds);
if(seconds < 0 && gameOver == false)
{
//Debug.Log(objectsPolished);
gameOver = true;
}
} }
void FixedUpdate() void FixedUpdate()
{ {
timer += Time.deltaTime;
float seconds = timeLimit - timer;
//Debug.Log((int)seconds);
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y); Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);
@@ -60,7 +54,7 @@ public class GameScript : MonoBehaviour
RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero); RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero);
if (hit.collider != null) if (hit.collider != null)
{ {
if (hit.collider.gameObject.tag == "Item" && !clicked) if (hit.collider.gameObject.tag == "Item" && !clicked && !gameOver)
{ {
pickedUpItem = hit.collider.gameObject; pickedUpItem = hit.collider.gameObject;
clicked = true; clicked = true;
@@ -93,10 +87,37 @@ public class GameScript : MonoBehaviour
pickedUpItem.transform.position = mousePos2D; pickedUpItem.transform.position = mousePos2D;
} }
if (GameObject.FindWithTag("Dirt") == null) { if(seconds < 0 && !gameOver)
Setup(); {
Debug.Log(objectsPolished);
gameOver = true;
clicked = false;
Cursor.visible = true;
if(pickedUpItem != null && pickedUpItem.name == "Rag")
{
pickedUpItem.transform.position = new Vector2(7.25f, 2.5f);
pickedUpItem.transform.rotation = Quaternion.identity;
} else if (pickedUpItem != null && pickedUpItem.name == "SprayBottle"){
pickedUpItem.transform.position = new Vector2(7.25f, -2.5f);
pickedUpItem.transform.rotation = Quaternion.identity;
}
Object.SetActive(false);
//Destorys all dirt and spray gameobjects left over that player didn't clean
GameObject[] leftovers = GameObject.FindGameObjectsWithTag("Dirt");
foreach(GameObject residue in leftovers)
GameObject.Destroy(residue);
}
if (!gameOver && GameObject.FindWithTag("Dirt") == null) {
objectsPolished++; objectsPolished++;
//Debug.Log("Beat the game/Next Level"); Setup();
//Debug.Log("GameOver");
} }
} }