コード例 #1
0
ファイル: GameManager.cs プロジェクト: Maareks/Endless-Cat
        private IEnumerator Revive()
        {
            dataManager.Revive();
            infiniteObjectGenerator.PrepareForRevive(false);
            cameraController.enabled = false;
            playerController.ResetValues(true);
            Transform playerTransform = playerController.transform;

            // Fire a raycast to determine where the paltform is. If a platform isn't directly under the character then move the platforms forward a small amount
            RaycastHit hit;
            int        retryCount = 0;

            if (playerTransform.forward != infiniteObjectGenerator.GetMoveDirection())
            {
                // reposition the player to be in the center of the platform
                playerController.UpdateForwardVector(infiniteObjectGenerator.GetMoveDirection());
            }
            Vector3 playerPosition = playerTransform.position;

            while (retryCount < 5)   // give up after 5 tries to prevent an infinite loop
            {
                yield return(new WaitForEndOfFrame());

                if (Physics.Raycast(playerPosition + 10000 * Vector3.up, Vector3.down, out hit, Mathf.Infinity, 1 << LayerMask.NameToLayer("Platform")))
                {
                    playerPosition.y = hit.point.y + playerController.GetComponent <CapsuleCollider>().center.y + 0.5f;
                    break;
                }
                infiniteObjectGenerator.PrepareForRevive(true);
                retryCount++;
            }

            // the position of the player has been determined. Reset the managers/controllers for a continued game
            powerUpManager.ResetValues();
            cameraController.ResetValues();
            if (chaseController != null)
            {
                chaseController.Reset(true);
            }
            cameraController.enabled = true;

            // Face the same direction as the path
            playerTransform.position = playerPosition;
            if (chaseController != null)
            {
                chaseController.transform.forward = playerTransform.forward;
            }
            StartGame(true);
        }