Exemple #1
0
    public virtual void Hit(Vector3 HitPosition, Vector3 HitDirection, float forceAmount = 0f)
    {
        if (IsDead)
        {
            return;
        }

        if (sendFurther && reciever)
        {
            reciever.Hit(HitPosition, HitDirection, forceAmount);
            return;
        }

        if (HitEffect)
        {
            int          layermask = 1 << gameObject.layer;
            RaycastHit2D hit       = Physics2D.RaycastAll(HitPosition - HitDirection, HitDirection, HitDirection.magnitude * 2f, layermask).FirstOrDefault(o => o.collider == collider2D);
            if (hit)
            {
                EntitySpawnManager.Spawn(HitEffectPoolName, HitPosition, Quaternion.FromToRotation(Vector3.back, hit.normal), countEntity: false, forceDirectSpawn: true);
                if (forceAmount != 0)
                {
                    Force(HitPosition, HitDirection.normalized, forceAmount);
                }
            }
        }
    }
Exemple #2
0
    private void Hit(GameObject other, Vector3 position)
    {
        if (other && other.GetComponent <HitAble>())
        {
            if (gameObjectHitted.Contains(other))
            {
                return;
            }

            HitAble target = other.GetComponent <HitAble>();
            target.Damage(new Damage()
            {
                DamageFromAPlayer = true,
                player            = player,
                amount            = damage,
                type  = DamageType.RANGED,
                other = player.transform
            });
            target.Hit(position, rigidbody2D.velocity * Time.fixedDeltaTime, force);

            gameObjectHitted.Add(other);

            AudioEffectController.Instance.PlayOneShot(HitEffect, transform.position);
        }
        else
        {
            EntitySpawnManager.InstantSpawn(hitEffektPoolName, position, Quaternion.identity, countEntity: false);

            EntitySpawnManager.Despawn(poolName, gameObject, false);
            return;
        }


        EntitySpawnManager.InstantSpawn(hitEffektPoolName, position, Quaternion.identity, countEntity: false);

        if (pierceCount >= pierceAmount)
        {
            rigidbody2D.velocity = Vector2.zero;
            GameObjectPool.Instance.Despawn(poolName, gameObject);
        }
        else
        {
            pierceCount++;
        }
    }