Esempio n. 1
0
        private void OnCollisionEnter2D(Collision2D collision)
        {
            if (controlEnabled && collision.transform.CompareTag(DataMgr.Instance.EnemyTag))
            {
                KinematicObject enemy           = collision.transform.GetComponent <KinematicObject>();
                Damageable      enemyDamageable = enemy.GetComponent <Damageable>();

                if (Bounds.center.y >= enemy.Bounds.max.y)
                {
                    //踩踏伤害
                    enemyDamageable.GetDamage(m_Damageable);
                    Bounce(trampleSpeed);
                }
                else
                {
                    //玩家受伤
                    m_Damageable.GetDamage(enemyDamageable);
                }
            }
            else if (!m_IsAlive && IsGrounded)
            {
                m_Move        *= 0;
                Time.timeScale = 1;
                IsFallToGround = true;
            }
        }
Esempio n. 2
0
        private void OnCollisionEnter2D(Collision2D collision)
        {
            bool isHitFXShowed = false;

            //敌人受伤并会被击退
            if (collision.transform.CompareTag(DataMgr.Instance.EnemyTag))
            {
                KinematicObject kObj       = collision.transform.GetComponent <KinematicObject>();
                Damageable      damageable = kObj.GetComponent <Damageable>();
                int             deathDir   = (int)Mathf.Sign(kObj.transform.position.x - transform.position.x);

                if (!damageable.GetDamage(damage, deathDir))
                {
                    return;
                }

                int sign = transform.right.x > 0 ? 1 : -1;

                if (!kObj.IsForwardWalled && !kObj.IsBackObstacled)
                {
                    kObj.transform.position += Vector3.right * beatBackPower * sign * Time.deltaTime;
                }
            }

            //显示击中特效
            foreach (ContactPoint2D point2D in collision.contacts)
            {
                if (isHitFXShowed)
                {
                    break;
                }

                FXDisplay hitFXDisplay = ObjPoolMgr.Instance.SpawnObj <FXDisplay>("pref_Hit");
                hitFXDisplay.transform.position = new Vector3(point2D.point.x, point2D.point.y, 0);
                hitFXDisplay.ShowFX();
                isHitFXShowed = true;
            }

            ObjPoolMgr.Instance.RecycleObj(gameObject);
        }