Beispiel #1
0
    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;
        }
    }
Beispiel #2
0
 public void RemoveBallFromPlay(BallBase ball)
 {
     if (BallsInPlay.Contains(ball))
     {
         BallsInPlay.Remove(ball);
     }
     Destroy(ball.gameObject, 1f);
 }