コード例 #1
0
    public void OnClickUnitDefinitionGui(UnitDefinitionGui unitDefinitionGui, int relatedCreatableUnitsIndex)
    {
        if (creatableUnits[relatedCreatableUnitsIndex].remainCoolTime != 0f)
        {
            Debug.Log("Still cooling.");
        }
        else if (currentCost < creatableUnits[relatedCreatableUnitsIndex].cost)
        {
            Debug.Log("Not enough cost.");
        }
        else
        {
            GameObject unitGo = Instantiate <GameObject>(creatableUnits[relatedCreatableUnitsIndex].prefab, gameStartPosition.transform.position, Quaternion.identity);
            unitGo.name = "Unit" + unitSeqNum++;
            MyBotAi myBotAi = unitGo.GetComponent <MyBotAi>();
            myBotAi.destroyOperationTarget = enemyBarrack;

            currentCost -= creatableUnits[relatedCreatableUnitsIndex].cost;
            creatableUnits[relatedCreatableUnitsIndex].remainCoolTime = creatableUnits[relatedCreatableUnitsIndex].coolTime;

            UpdateGuisAboutCost();

            StartCoroutine(CoolTimeReductionCoroutine(relatedCreatableUnitsIndex));
            unitDefinitionGui.StartCoolTimeDisplayUpdate();
        }
    }
コード例 #2
0
 public static bool IsSameSide(this MyBotAi thisBot, MyBotAi otherBot)
 {
     if (thisBot.destroyOperationTarget == otherBot.destroyOperationTarget)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #3
0
    public void CreateEnemy()
    {
        int index = Mathf.FloorToInt(UnityEngine.Random.Range(0, creatableEnemies.Length));

        index = Mathf.Max(index, creatableEnemies.Length - 1);

        if (creatableEnemies[index].currentCount < creatableEnemies[index].maximumCreatableNumber)
        {
            GameObject unitGo = Instantiate <GameObject>(creatableEnemies[index].prefab, enemyGameStart.transform.position, Quaternion.identity);
            creatableEnemies[index].currentCount++;
            unitGo.name = "Enemy" + enemySeqNum++;

            MyBotAi myBotAi = unitGo.GetComponent <MyBotAi>();
            myBotAi.destroyOperationTarget = playerBarrack;

            MyUnit myUnit = unitGo.GetComponent <MyUnit>();
            myUnit.RuleManager.overridedGameRule = new EnemyUnitGameRule(index);
        }
    }
コード例 #4
0
    protected override void OnHitShotBullet(GunSlinger shooter, Gun usedGun, Bullet bullet, Collider2D collider)
    {
        TriggerVolume triggerVolume = collider.gameObject.GetComponent <TriggerVolume>();

        if (triggerVolume != null)
        {
            switch (triggerVolume.type)
            {
            case TriggerVolume.Type.EnemyBarrack:
                //Debug.Log(shooter + " hits EnemyBarrack!");
                bullet.Ricochet();
                break;

            case TriggerVolume.Type.OurBarrack:
                //Debug.Log(shooter + " hits OurBarrack!");
                bullet.Ricochet();
                break;

            default:
                break;
            }
        }
        else
        {
            MyUnit  hittedUnit = collider.gameObject.GetComponent <MyUnit>();
            MyBotAi hittedAi   = collider.gameObject.GetComponent <MyBotAi>();
            if (hittedUnit != null && hittedAi != null && !hittedUnit.IsDead)
            {
                MyUnit  shotUnit = shooter.GetComponent <MyUnit>();
                MyBotAi shotAi   = shooter.GetComponent <MyBotAi>();

                if (shotUnit != null && shotAi != null)
                {
                    if (!shotAi.IsSameSide(hittedAi))
                    {
                        bullet.Ricochet();
                        hittedUnit.TakeDamage(0.5f);
                    }
                }
            }
        }
    }
コード例 #5
0
    void Sight.ISubscriber.OnEnter(GameObject enteringObject, IReadOnlyList <GameObject> existingObject)
    {
        MyBotAi ai = enteringObject.GetComponent <MyBotAi>();

        if (ai != null && ai.destroyOperationTarget != destroyOperationTarget)
        {
            if (currentDestroyTarget == null)
            {
                currentDestroyTarget = enteringObject;
            }
            else
            {
                float currentTargetDistance  = Vector2.Distance(transform.position, currentDestroyTarget.transform.position);
                float enteringTargetDistance = Vector2.Distance(transform.position, enteringObject.transform.position);
                if (enteringTargetDistance < currentTargetDistance)
                {
                    currentDestroyTarget = enteringObject;
                }
            }
        }
    }