Пример #1
0
        private void Awake()
        {
            Debug.Log("Entity -" + name);
            //加载组件
            animator         = GetComponent <Animator>();
            shootingBehavior = GetComponent <ShootingBehavior>();
            movingBehavior   = GetComponent <MovingBehavior>();
            hitBehavior      = GetComponent <HitBehavior>();
            collider         = GetComponent <Collider2D>();
            rigidbody        = GetComponent <Rigidbody2D>();
            stat             = GetComponent <Stats>();

            //音效初始化
            if (shootingBehavior != null)
            {
                shootingBehavior.audio = usingAudio;
            }

            if (movingBehavior != null)
            {
                movingBehavior.audio = usingAudio;
            }

            if (hitBehavior != null)
            {
                hitBehavior.audio = usingAudio;
            }

            PickingBehavior pickingBehavior = GetComponent <PickingBehavior>();

            if (pickingBehavior != null)
            {
                pickingBehavior.audio = usingAudio;
            }
        }
Пример #2
0
        public override void Initialize()
        {
            base.Initialize();

            Body.Mass = 65f;

            followingBehaviour = GetComponent <FollowingBehavior <BoarState> >();
            fleeingBehaviour   = GetComponentByName <FleeingBehavior <BoarState> >("fleeing");
            hitBehaviour       = GetComponentByName <HitBehavior <BoarState> >("beinghit");
            aiComponent.WithTrigger(FleeingTrigger).WithTrigger(FollowingTrigger);
        }
Пример #3
0
        protected override void OnHit(GameObject hitObject, Vector3 hitPos, Vector3 hitDirection)
        {
            HitBehavior hit  = hitObject.GetComponent <HitBehavior>();
            Stats       stat = hitObject.GetComponent <Stats>();

            if (hit != null && stat != null)
            {
                Debug.Log("Deal Damage to" + hitObject.name);
                damage.DealDamage(hit, stat, hitDirection.normalized);
            }
        }
        protected override void OnHit(GameObject hitObject, Vector3 hitPos, Vector3 hitDirection)
        {
            //Debug.Log($"hit {hitObject.name}");
            HitBehavior hit  = hitObject.GetComponent <HitBehavior>();
            Stats       stat = hitObject.GetComponent <Stats>();

            if (hit != null && stat != null)
            {
                damage.DealDamage(hit, stat, hitDirection.normalized);
            }

            collider.enabled = false;

            //todo:击中效果优化,击中玩家没有效果
            EffectPool.instance.PlayEffect("hit_effect", hitPos, hitDirection);
            DestroyProjectile();
        }
Пример #5
0
 public override void DealDamage(HitBehavior hitBehavior, Stats stat, Vector2 direction, bool isTouchDamage)
 {
     hitBehavior.GetHit(damage, knockbackForce, direction, isTouchDamage);
 }
Пример #6
0
 /// <summary>
 /// 根据stat计算实际伤害,将异常状态和实际伤害传输给受击行为
 /// </summary>
 /// <param name="stat">人物属性</param>
 /// <param name="hitBehavior">受击后行为</param>
 /// <param name="direction">受击方向,只有x轴</param>
 abstract public void DealDamage(HitBehavior hitBehavior, Stats stat, Vector2 direction, bool isTouchDamage = false);