예제 #1
0
    public void Attack(int damage)
    {
        if (!_cooldownTimer.IsDone)
        {
            return;
        }

        InstantiatedAudioPlayer.PlaySound(GetComponent <AudioClipData>(), transform.position);

        GetComponent <Animator>().SetTrigger("Attacking");

        _cooldownTimer.Reset();
        var direction  = GetComponent <TopDownController>().Direction;
        var collisions =
            Physics2D.OverlapBoxAll(
                new Vector2(transform.position.x, transform.position.y) + direction * (AttackRange / 2),
                new Vector2(AttackWidth, AttackRange), Vector2.SignedAngle(Vector2.up, direction), EnemyLayers);

        foreach (var collision in collisions)
        {
            var target = collision.GetComponent <Combateer>();
            if (target)
            {
                target.TakeDamage(damage);
                var distance = (target.transform.position - transform.position).normalized * KnockbackDistance;
                target.TakeKnockback(new Vector2(distance.x, distance.y), KnockbackTime);
            }
        }
    }
예제 #2
0
파일: Pickup.cs 프로젝트: Ansoulom/Survival
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.CompareTag("Player"))
     {
         other.GetComponent <Inventory>().AddResource(Resource);
         InstantiatedAudioPlayer.PlaySound(GetComponent <AudioClipData>(), transform.position);
         DestroyObject(gameObject);
     }
 }
예제 #3
0
 private void TakeDamage(int damage)
 {
     if (Invincible)
     {
         return;
     }
     InstantiatedAudioPlayer.PlaySound(GetComponents <AudioClipData>()[1], transform.position);
     Health -= damage;
     if (Health <= 0)
     {
         Kill();
     }
 }
예제 #4
0
    private void UpdateAggro()
    {
        var distance = (_player.transform.position - transform.position).magnitude;

        if (_aggro)
        {
            if (distance > DeaggroRange)
            {
                _aggro = false;
            }
        }
        else
        {
            if (distance < AggroRange)
            {
                _aggro = true;
                InstantiatedAudioPlayer.PlaySound(GetComponents <AudioClipData>()[2], transform.position);
            }
        }
    }