示例#1
0
    public override void OnTriggerEnter2D(Collider2D other)
    {
        if (Source == null || other.gameObject == Source || _triggered)
        {
            return;
        }

        if (other.gameObject.layer == LayerMask.NameToLayer("Walls"))
        {
            m_Anim.SetTrigger(m_collideHash);
            _triggered = true;
        }
        else
        {
            Enemy enemy = other.gameObject.GetComponent <Enemy>();
            if (enemy != null)
            {
                //    m_Anim.SetTrigger(m_collideHash);
                //    enemy.Hit(HitDamage);
                //    _triggered = true;
                //}


                /*if (Source.GetComponent<Player>().IsAttackLongCasted())
                 *  enemy.Hit(MagicShotLongAttackDamageValue);
                 * else*/
                enemy.Hit(HitDamage);


                if (enemy.IsBumpable)
                {
                    enemy.Bump(this.transform.position, BumpForce);
                }
                m_Anim.SetTrigger(m_collideHash);
                _triggered = true;
            }

            BushScript otherBushScript = other.gameObject.GetComponent <BushScript>();
            if (otherBushScript != null)
            {
                otherBushScript.hit();
                m_Anim.SetTrigger(m_collideHash);
                _triggered = true;
            }
        }
    }
    void OnTriggerEnter2D(Collider2D other)
    {
        Player player = other.gameObject.GetComponent <Player> ();

        if (player != null && player.m_BeingHit == false)
        {
            if (player._isInCounterTime)
            {
                m_IATest.startCounter();
            }
            else
            {
                Vector2      dir = other.bounds.center - transform.position;
                RaycastHit2D hit = Physics2D.Raycast(transform.position, dir, 200f, LayerMask.GetMask("Player"));

                if (m_IATest.IsAttackLongCasted())
                {
                    player.Hit(m_IATest, LongAttackDamageValue, StaminaConsomation);
                }
                else
                {
                    player.Hit(m_IATest, DamageValue, StaminaConsomation);
                }

                Instantiate(HitPrefab, hit.point, Quaternion.identity);
            }
        }

        BushScript otherBushScript = other.gameObject.GetComponent <BushScript>();

        if (otherBushScript != null)
        {
            Vector2      dir = other.bounds.center - transform.position;
            RaycastHit2D hit = Physics2D.Raycast(transform.position, dir, 200f, LayerMask.GetMask("Objects"));
            Instantiate(HitPrefab, hit.point, Quaternion.identity);

            otherBushScript.hit();
        }
    }
    void OnTriggerEnter2D(Collider2D other)
    {
        Enemy enemy = other.gameObject.GetComponent <Enemy> ();

        if (enemy != null)
        {
            Vector2      dir = other.bounds.center - transform.position;
            RaycastHit2D hit = Physics2D.Raycast(transform.position, dir, 200f, LayerMask.GetMask("Enemy"));
            m_Camera.setShake(0.5f, 5);

            if (enemy.m_BeingHit == false)
            {
                m_Player.DoHitEnemy(enemy);

                ImpactFeedback impact = m_ImpactFeedbackManager.getUsableImpact();
                if (impact != null)
                {
                    impact.pop(hit.point);
                }
            }

            dir.Normalize();
            enemy.GetComponent <Rigidbody2D>().AddForceAtPosition(BumpForce * dir, hit.point);
        }

        BushScript otherBushScript = other.gameObject.GetComponent <BushScript>();

        if (otherBushScript != null)
        {
            Vector2        dir    = other.bounds.center - transform.position;
            RaycastHit2D   hit    = Physics2D.Raycast(transform.position, dir, 200f, LayerMask.GetMask("Objects"));
            ImpactFeedback impact = m_ImpactFeedbackManager.getUsableImpact();
            impact.pop(hit.point);

            otherBushScript.hit();
        }
    }