// Since we're doing physics work, we use FixedUpdate instead of Update.
        void FixedUpdate()
        {
            if (IsProcessingDeath)
            {
                return;
            }

            Rigidbody rigidBody = GetComponent <Rigidbody>();

            Vector2 input = inputController.GetInputVector();

            rigidBody.AddForce(new Vector3(input.x, 0, input.y));

            if (transform.position.y < kFellOffLevelHeight)
            {
                if (OnFallSpawn != null)
                {
                    // Spawn in the death particles. Note that the particles should clean themselves up.
                    Instantiate(OnFallSpawn, transform.position, Quaternion.identity);

                    // We don't want the ball to keep the ball where it died, so that the camera can
                    // see the on death particles before respawning.
                    IsProcessingDeath     = true;
                    rigidBody.isKinematic = true;
                    // Disable the children, which have the visible components of the ball.
                    foreach (Transform child in transform)
                    {
                        child.gameObject.SetActive(false);
                    }
                    StartCoroutine(DelayedResetLevel());
                }
            }
        }
Esempio n. 2
0
        // Since we're doing physics work, we use FixedUpdate instead of Update.
        void FixedUpdate()
        {
            if (IsProcessingDeath)
            {
                return;
            }

            Vector2   input     = inputController.GetInputVector();
            Rigidbody rigidBody = GetComponent <Rigidbody>();

            rigidBody.AddForce(new Vector3(input.x, 0, input.y));

            if (transform.position.y < kFellOffLevelHeight)
            {
                EndGame();
            }
        }