Exemple #1
0
        public void Die()
        {
            Debug.Log($"{name} has died!");
            Destroy(gameObject, 2f);

            Rigidbody rb = GetComponent <Rigidbody>();

            if (rb)
            {
                rb.constraints = RigidbodyConstraints.None;
            }
            if (_killSound)
            {
                _killSound.PlayAudio();
            }
        }
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            _jumpSound.PlayAudio();
        }

        if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.S))
        {
            _run.PlayAudio();
        }
        else if (Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.S))
        {
            _run.StopAudio();
        }
    }
Exemple #3
0
        public void Hit(int damage)
        {
            hitPoints = Math.Max(hitPoints - damage, 0);
            Debug.Log($"{name} was hit for {damage} damage!");

            if (_healthBar)
            {
                _healthBar.SetHealth(hitPoints);
            }

            if (IsDead())
            {
                Die();
            }
            else if (_damageSound)
            {
                _damageSound.PlayAudio();
            }
        }