Fix

1 merge request!5Merge from develop into master
Showing with 24 additions and 6 deletions
+24 -6
using System.Collections.Generic; using System;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using TMPro; using TMPro;
...@@ -18,6 +19,9 @@ public class BallThrower : MonoBehaviour ...@@ -18,6 +19,9 @@ public class BallThrower : MonoBehaviour
private bool gameOver = true; private bool gameOver = true;
private float remainingTime; private float remainingTime;
private GameObject currentBall; private GameObject currentBall;
private GameObject ball1;
private GameObject ball2;
private GameObject ball3;
private List<GameObject> goList = new List<GameObject>(); private List<GameObject> goList = new List<GameObject>();
private void Start() private void Start()
...@@ -32,7 +36,6 @@ private void SpawnBall(Transform h) ...@@ -32,7 +36,6 @@ private void SpawnBall(Transform h)
{ {
currentBall = Instantiate(ballPrefab, h.position, Quaternion.identity); currentBall = Instantiate(ballPrefab, h.position, Quaternion.identity);
Rigidbody ballRigidbody = currentBall.GetComponent<Rigidbody>(); Rigidbody ballRigidbody = currentBall.GetComponent<Rigidbody>();
ballRigidbody.isKinematic = false;
goList.Add(currentBall); goList.Add(currentBall);
currentBall = null; currentBall = null;
} }
...@@ -49,10 +52,10 @@ private void Update() ...@@ -49,10 +52,10 @@ private void Update()
remainingTime -= Time.deltaTime; remainingTime -= Time.deltaTime;
if (remainingTime <= 0) if (remainingTime <= 0)
{ {
foreach (GameObject obj in goList) DestroyBalls();
{ //Destroy(ball1);
Destroy(obj); //Destroy(ball2);
} //Destroy(ball3);
timerText.text = "0"; timerText.text = "0";
gameOver = true; gameOver = true;
} }
...@@ -62,6 +65,20 @@ private void Update() ...@@ -62,6 +65,20 @@ private void Update()
} }
} }
private void DestroyBalls()
{
try
{
foreach (GameObject obj in goList)
{
Destroy(obj);
}
}
catch (Exception e)
{
DestroyBalls();
}
}
public void StartGame() public void StartGame()
{ {
if (!gameOver) return; if (!gameOver) return;
...@@ -71,6 +88,7 @@ public void StartGame() ...@@ -71,6 +88,7 @@ public void StartGame()
SpawnBall(ballSpawnPos1); SpawnBall(ballSpawnPos1);
SpawnBall(ballSpawnPos2); SpawnBall(ballSpawnPos2);
SpawnBall(ballSpawnPos3); SpawnBall(ballSpawnPos3);
Debug.LogError(goList);
remainingTime = startTime; remainingTime = startTime;
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment