예제 #1
0
    /// <summary>
    /// 添加一个定时销毁器
    /// </summary>
    /// <param name="onThis"></param>
    /// <param name="timeInSeconds"></param>
    /// <param name="callDespawn"></param>
    /// <returns></returns>
    public static Lifetimer AddTimer(GameObject onThis, float timeInSeconds, bool callDespawn)
    {
        Lifetimer omg = onThis.AddComponent <Lifetimer>();

        omg.Lifetime    = timeInSeconds;
        omg.CallDespawn = callDespawn;

        return(omg);
    }
예제 #2
0
        public void Attack()
        {
            if (ready)
            {
                Hit hit = new Hit();
                switch (attackModel)
                {
                case AttackModel.longRange:
                    hit.sender       = gameObject.name;
                    hit.hit          = equip.attack;
                    hit.hitFrequency = equip.numberAttacks;
                    hit.hitType      = equip.hitType;
                    break;

                case AttackModel.closeCombat:
                    hit.sender  = gameObject.name;
                    hit.hit     = equip.closeCombatAttack;
                    hit.hitType = equip.hitType;
                    break;

                case AttackModel.none:
                    return;
                }
                if (target != null)
                {
                    switch (equip.shootType)
                    {
                    case ShootType.gun:
                        if (equip.muzzleFlame != null)
                        {
                            GameObject b = Instantiate <GameObject>(equip.muzzleFlame, equipAttackPosition, Quaternion.identity);
                            Lifetimer.AddTimer(b, 1.5f, true);
                        }
                        AttackCallBack(this, hit);
                        target.Recipient(hit);    //即时的hit
                        break;

                    case ShootType.ballistic:
                        //todo 弹道发射hit
                        break;

                    case ShootType.closeCombat:
                        AttackCallBack(this, hit);
                        target.Recipient(hit);    //即时的hit
                        break;
                    }

                    ready = false;
                }
            }
        }