Esempio n. 1
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);
        }