Beispiel #1
0
    void Shot()
    {
        // Пускаем лучь
        Ray        ray = new Ray(fierPoint.position, fierPoint.forward * 10f);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, 500f, 13, QueryTriggerInteraction.Ignore))
        {
            // Если попали во врага, наносим урон
            IDamagable enemy = hit.transform.gameObject.GetComponent <IDamagable>();
            if (enemy != null)
            {
                enemy.GetDamage(damage);
            }

            // Устанавливаем декаль
            GameObject g = Instantiate <GameObject>(Dec);
            g.transform.position = hit.point + hit.normal * 0.01f;
            g.transform.rotation = Quaternion.LookRotation(-hit.normal);
            g.transform.SetParent(hit.transform);
            Rigidbody r = hit.transform.gameObject.GetComponent <Rigidbody>();
            if (r != null)
            {
                r.AddForceAtPosition(-hit.normal * 500, hit.point);
            }
        }
        Partial.Play();
    }
Beispiel #2
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == enemyTag)
     {
         IDamagable enemy = collision.gameObject.GetComponent <IDamagable>();
         enemy.GetDamage(Damage);
         Destroy(gameObject);
     }
 }
Beispiel #3
0
    public virtual void DoDamage()
    {
        IDamagable Damagable = Target.GetComponent <IDamagable>();

        if (Damagable != null)
        {
            Damagable.GetDamage(atackdamage);
        }
    }
Beispiel #4
0
    private void OnTriggerEnter(Collider other)
    {
        //myAnimator.animat
        IDamagable enemy = other.GetComponent <IDamagable>();

        if (enemy != null)
        {
            enemy.GetDamage(damage);
        }
    }
Beispiel #5
0
 protected virtual void Attack()
 {
     if (targetEnemy != null)
     {
         IDamagable damagable = targetEnemy.GetComponent <IDamagable>();
         if (damagable != null)
         {
             damagable.GetDamage(attackDamage);
         }
     }
 }
Beispiel #6
0
    private void OnTriggerEnter(Collider other)
    {
        IDamagable enemy = other.GetComponent <IDamagable>();

        if (enemy != null)
        {
            if (other.tag == "Enemy")
            {
                enemy.GetDamage(2f);
                //other.GetComponent<Enemy>().TakeDamage(1);
                Destroy(gameObject, 2f);
            }
        }
    }
Beispiel #7
0
    protected virtual void DamageTarget(GameObject target)
    {
        IDamagable damagable = target.GetComponent <IDamagable>();

        if (damagable != null)
        {
            damagable.GetDamage(Damage);
            damageMultiplier = 1;
            if (OnDamageSomething != null)
            {
                OnDamageSomething(target.transform);
            }
        }
    }
Beispiel #8
0
    /// <summary>
    /// returning object to the pool updating the score if it hit something.
    /// </summary>
    /// <param name="_coll"></param>
    public override void OnCollisionEnter(Collision _coll)
    {
        IDamagable _damagable = _coll.gameObject.GetComponent <IDamagable>();

        if (_coll.gameObject.layer == LayerMask.NameToLayer("Ground") || _damagable != null)
        {
            if (_damagable != null)
            {
                _damagable.GetDamage(damage);
                ScoreManager.Instance.UpdateScore(-1, 0);
            }

            Pool.Instance.ReturnObjectToPool <Block>(this);
            onHitGround?.Invoke(this);
        }
    }
Beispiel #9
0
    void PerformAttack()
    {
        canAttack = false;
        animator.SetTrigger(attackTriggerId);

        Collider2D[] hits = Physics2D.OverlapCircleAll(attackHolder.position, attackRadius, enemyLayerMask);

        foreach (Collider2D hit in hits)
        {
            IDamagable damagable = hit.gameObject.GetComponent <IDamagable>();
            if (damagable != null)
            {
                damagable.GetDamage(attackDamage, transform);
            }
        }
    }
Beispiel #10
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag != "Player" && other.tag != "Trigger")
        {
            rb.velocity   = new Vector3(0, 0, 0);
            rb.useGravity = false;

            IDamagable enemy = other.GetComponent <IDamagable>();
            if (enemy != null)
            {
                enemy.GetDamage(damage);
            }

            damage = 0;
        }
    }
Beispiel #11
0
    protected void OnTriggerEnter2D(Collider2D collision)
    {
        IDamagable obj1 = collision.gameObject.GetComponent <IDamagable>();

        if (obj1 != null)
        {
            obj1.GetDamage(Damage);
            if (!b_Penetrating)
            {
                Destroy(this.gameObject);
            }
        }
        else
        {
            Destroy(this.gameObject);
        }
    }
Beispiel #12
0
    IEnumerator Move(Transform target, float bulletSpeed, int bulletDamage)
    {
        while (target == null || Vector3.Distance(_transform.position, target.position) > LvlManager.instance.WorldCellSize)
        {
            _transform.position += _transform.forward * bulletSpeed * Time.deltaTime;
            yield return(null);
        }

        if (target != null)
        {
            IDamagable damagable = target.GetComponent <IDamagable>();
            if (damagable != null)
            {
                damagable.GetDamage(bulletDamage);
            }
        }
        Destroy(gameObject);
    }
Beispiel #13
0
 private void OnTriggerEnter(Collider other)
 {
     if (!other.CompareTag("Player"))
     {
         IDamagable enemy = other.GetComponent <IDamagable>();
         if (enemy != null)
         {
             if (explosion != null)
             {
                 var expl = Instantiate(explosion);
                 expl.transform.position = gameObject.transform.position;
             }
             else
             {
                 enemy.GetDamage(damage);
             }
             Destroy(gameObject);
         }
     }
 }