private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag.Equals("HawkBall")) { HawkBall ball = collision.GetComponent <HawkBall>(); ballManager.balls.Remove(ball); ball.Die(); } }
internal void spawnBalls(Vector3 position, int count) { for (int i = 0; i < count; i++) { HawkBall spawnedBall = Instantiate(ballPrefab, position, Quaternion.identity) as HawkBall; Rigidbody2D spawnedBallRb = spawnedBall.GetComponent <Rigidbody2D>(); spawnedBallRb.velocity = new Vector2(0, initialBallSpeed); balls.Add(spawnedBall); } }
private void InitBall() { // reset list here to avoid null errors balls = new List <HawkBall>(); Vector3 paddlePosition = paddle.gameObject.transform.position; Vector3 startingPosition = new Vector3(paddlePosition.x, paddlePosition.y + .27f, 0); initialBall = Instantiate(ballPrefab, startingPosition, Quaternion.identity); initialBallRB = initialBall.GetComponent <Rigidbody2D>(); balls.Add(initialBall); }
void ApplyBallCollision(HawkBall ball) { hitPoints--; if (hitPoints <= 0) { brickManager.remainingBricks.Remove(this); onBrickDestruction?.Invoke(this); DestroyEffect(); Destroy(gameObject); } else { sr.sprite = brickManager.sprites[hitPoints - 1]; } }
// All lives lost. Clear everything then show death screen void onDeath(HawkBall ball) { if (ballManager.balls.Count <= 0) { lives--; collectableManager.resetCollectables(); // reset balls // stop game // reload level ballManager.resetBalls(); onLifeLost?.Invoke(lives); isgameStarted = false; brickManager.reloadBricks(); if (lives < 1) { gameOverScreen.SetActive(true); } } }
void OnCollisionEnter2D(Collision2D collision) { HawkBall ball = collision.gameObject.GetComponent <HawkBall>(); ApplyBallCollision(ball); }