示例#1
0
    void Update()
    {
        if (PauseMenuController.GameIsPaused == false && view.animator != null)
        {
            model.newPosition = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
            CheckForDoors();

            // Check if player should be dead
            if (model.health <= 0.0f)
            {
                FindObjectOfType <AudioManager>().Play("Player Dead");
                playerHealthScript.UpdateHealth();
                playerHealthScript.InitiateGameOver();
                view.SetDead(true);
                gameOverMenu.EnableGameOver();
                model.rigidBody.velocity = new Vector3(0, 0, 0); // Stop player movement

                // Disable MVC
                model.enabled = false;
                view.enabled  = false;
                this.enabled  = false;
            }

            HealthPickup();

            if (Time.time >= model.nextAttackTime)
            {
                if (Input.GetKey(KeyCode.Mouse0))
                {
                    FindObjectOfType <AudioManager>().Play("Melee");
                    view.swordAnimator.SetTrigger("Attack");
                    meleeWeaponScript.Attack();
                    model.nextAttackTime = Time.time + 1f / model.meleeAttackRate;
                }
                else if (Input.GetKey(KeyCode.Mouse1))
                {
                    FindObjectOfType <AudioManager>().Play("Shoot");
                    rangedWeaponScript.Attack(model.rangedAttackPattern.ToString());
                    model.nextAttackTime = Time.time + 1f / model.rangedAttackRate;
                }
            }
        }
    }