Example #1
0
 private void Update()
 {
     LookAtMouse();
     if (Input.GetKey(KeyCode.Backslash))
     {
         float lostHealth = _playerHealth.HealthMax - _playerHealth.Health;
         if (lostHealth > 0f)
         {
             _playerHealth.DealDamage(-lostHealth);
         }
     }
 }
Example #2
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        string otherColliderTag = other.gameObject.tag;

        if ("Wall" == otherColliderTag)
        {
            Destroy(gameObject);
            AudioClipPlayer.PlayAudioAtLocation(soundWall, _transform.position, 0.5f);
            return;
        }

        if (_isDisabled)
        {
            return;
        }

        switch (otherColliderTag)
        {
        case "Player":
        case "Enemy":
            IHealthSystem otherHealthSystem = other.GetComponent <IHealthSystem>();
            otherHealthSystem.DealDamage(damage);
            Destroy(gameObject);
            AudioClipPlayer.PlayAudioAtLocation(soundDamage, _transform.position);
            break;

        case "Mirror" when canBeDeflected:
            Transform mirrorTransform = other.transform;
            if (IsProjectileCollidingWithFrontOfMirror(mirrorTransform, _transform.position))
            {
                Vector2 reflectionVector = Vector2.Reflect(transform.right, mirrorTransform.right);
                _transform.right      = reflectionVector.normalized;
                _rigidbody2D.velocity = Vector2.zero;
                _rigidbody2D.AddForce(LaunchVector);
                DelayCollisions();
                AudioClipPlayer.PlayAudioAtLocation(soundReflection, _transform.position, 0.5f);
            }
            break;
        }
    }