Example #1
0
 private void Update()
 {
     if (Seconds <= 0)
     {
         bar.SetActive(false);
     }
     text.text = "HP:" + unitBase.GetHP().ToString();
     CheckHPChange();
     //Debug.Log(unitBase.gameObject);
     Seconds -= Time.deltaTime;
 }
Example #2
0
    private IEnumerator attackTarget(UnitBase from, UnitBase target, bool canFightBack)
    {
        from.CanOperate = false;
        yield return(from.Anim_OnAttack());

        //发射子弹
        ResManager.Get().LoadAsync <GameObject>("Prefabs/Units/Projectile/Projectile", (obj) =>
        {
            //设置起始位置
            Vector3 po             = from.transform.position;
            po.y                   = from.GetComponent <UnitBase>().Height;
            obj.transform.position = po;
            //朝向攻击目标
            obj.transform.LookAt(target.transform);
            Quaternion rotation = obj.transform.rotation;
            //将上下旋转重置为0
            rotation.x             = 0;
            obj.transform.rotation = rotation;
            //初始化子弹逻辑
            obj.GetComponent <Projectile>().Init(target.gameObject, () => {
                //子弹到达攻击目标
                target.CostHP(from.Damage);
                ResManager.Get().LoadAsync <GameObject>("Prefabs/VFX/ParticleExplosion/ParticleExplosion", (vfx) => {
                    vfx.transform.position = obj.transform.position;
                });
                target.Anim_OnDamage();
                //若对方未死亡,则回击
                if (canFightBack && target.GetHP() > 0)
                {
                    target.Attack(from, true, true);
                }
            }, 1f);
        });
    }
Example #3
0
    IEnumerator attack(UnitBase from, UnitBase target, bool canFightBack)
    {
        yield return(DT_MoveTo(from, target));

        if (target == null)
        {
            yield break;
        }
        if (from.triumph)
        {
            from.AddHP(1);
        }
        if (from.dualAttack)
        {
            yield return(DT_MoveTo(from, target));
        }
        if (target.GetHP() > 0f && canFightBack)
        {
            target.Attack(from, true, false);
        }
    }