Beispiel #1
0
    void Update()
    {
        if (playerAttr.currentHP <= 0)
        {
            playerAttr.isDead    = true;
            playerAttr.currentHP = 0;
        }

        if (playerAttr.currentHP > playerAttr.maxHP)
        {
            playerAttr.currentHP = playerAttr.maxHP;
        }

        if (!playerAttr.isDead)
        {
            float moveHorizontal = Input.GetAxis("Horizontal");
            float moveVertical   = Input.GetAxis("Vertical");

            Vector3 movement = new Vector3(moveVertical, 0, -moveHorizontal);
            m_rigidbody.velocity = movement * playerAttr.walkSpeed;

            if (Input.GetKeyDown(KeyCode.W))
            {
                m_animator.SetFloat("xPos", 0);
                m_animator.SetFloat("yPos", 1);
            }
            if (Input.GetKeyDown(KeyCode.S))
            {
                m_animator.SetFloat("xPos", 0);
                m_animator.SetFloat("yPos", -1);
            }
            if (Input.GetKeyDown(KeyCode.D))
            {
                m_animator.SetFloat("xPos", 1);
                m_animator.SetFloat("yPos", 0);
            }
            if (Input.GetKeyDown(KeyCode.A))
            {
                m_animator.SetFloat("xPos", -1);
                m_animator.SetFloat("yPos", 0);
            }

            if (gunEquipped != null)
            {
                weaponsBehaviour = gunEquipped.GetComponent <WeaponsBehaviour>();
                if (Input.GetKeyDown(KeyCode.Space) && weaponsBehaviour.clipSize > 0)
                {
                    weaponsBehaviour.StartCoroutine("Shoot");
                }
                if (Input.GetKeyDown(KeyCode.Q))
                {
                    gunEquipped.transform.parent = null;
                    gunEquipped = null;
                }
            }

            if ((Input.GetKeyDown(KeyCode.F)) && (playerAttr.amountOfMedKits >= 1 && playerAttr.currentHP < 100))
            {
                playerAttr.currentHP       += 20;
                playerAttr.amountOfMedKits -= 1;
                if (playerAttr.currentHP > 100)
                {
                    playerAttr.currentHP = 100;
                }
            }
        }
    }