/// <summary> /// Spawn new ball and destroy self when out of game /// </summary> void OnBecameInvisible() { // death timer destruction is in Update //if (!deathTimer.Finished) if (deathTimer.Running) //scam { // only spawn a new ball if below screen float halfColliderHeight = gameObject.GetComponent <BoxCollider2D>().size.y / 2; if (transform.position.y - halfColliderHeight < ScreenUtils.ScreenBottom) { //Camera.main.GetComponent<BallSpawner>().SpawnBall(); // HUD.ReduceBallsLeft(); ballsLeftEvent.Invoke(); AudioManager.Play(AudioClipName.BallLost); } Destroy(gameObject); } }
void Update() { if (timer.Finished) { //ballsLeftEvent.Invoke(); ballSpawner.SpawnBall(); Destroy(gameObject); } else if (rigidBody2D.position.y < (ScreenUtils.ScreenBottom - 0.2f)) { ballsLeftEvent.Invoke(); ballSpawner.SpawnBall(); Destroy(gameObject); } if (speedupBall) { if (speedupTimer.Finished) { rigidBody2D.velocity = rigidBody2D.velocity / speedupFactor; speedupBall = false; } } }