private void Update() { bool isKeyDown = GamePad.GetButtonDown(GamePad.Button.Y, GamePad.Index.Any) || Input.GetKeyDown(KeyCode.Space); if (isKeyDown) { BallBase ball = BallPool.TryTakeBallToPlay(); if (ball != null) { ball.enabled = false; Vector2 pos = PhysicsTools.GetRandomPositionBetweenVectors(BallSpawnPositionMin.position, BallSpawnPositionMax.position); ball.SetGravityState(false); ball.ResetTrailEmitter(); ball.transform.position = pos; ball.Rigidbody.velocity = Vector2.zero; ball.Rigidbody.AddForce(Vector2.down * PhysicsConstants.BallSpeedAtStart, ForceMode2D.Impulse); BallsInPlay.Add(ball); ball.ResetLastFrameVelocityAndPosition(); ball.enabled = true; } CallOnGameStateChanged(); GameStarted = true; EnemyController.Instance.TryInitEnemySpawning(); } if (GameStarted) { GameTime += Time.deltaTime; } }
private void AddBallToPool() { Vector3 randomPos = PhysicsTools.GetRandomPositionBetweenVectors(BallSpawnPlaceMin.position, BallSpawnPlaceMax.position); BallBase ball = Instantiate(BallPrefab, randomPos, Quaternion.identity); ball.SetGravityState(true); ballsInPool.Add(ball); ball.gameObject.name = "Ball " + ballCounter; ballCounter++; GameController.Instance.CallOnGameStateChanged(); }