Esempio n. 1
0
    public void HandleOnDamagedByWeapon(WeaponComponent weapon, HealthComponent target)
    {
        Vector3 hitDirection = target.transform.position - weapon.transform.position;
        var     body         = target.GetComponent <Rigidbody2D>();

        if (body != null)
        {
            body.AddForce(hitDirection.normalized * weapon.PushPower);
        }

        StunWalking(target.GetComponent <MovementComponent>());

        target.Health = Mathf.Max(0, target.Health - weapon.Damage);
        _hitSound.PlayMutated();

        var flash = target.GetComponentInChildren <SpriteFlash>();

        if (flash != null)
        {
            DOTween.Sequence()
            .AppendCallback(() => flash.WhiteSprite())
            .Append(Camera.main.transform.DOShakePosition(0.1f, 0.1f))
            .AppendCallback(() => flash.NormalSprite());
        }
        Thread.Sleep(30);
    }