Exemple #1
0
        //method called when the APC requests nearby units to enter.
        public void CallUnits()
        {
            AudioManager.Play(FactionEntity.AudioSourceComp, callUnitsAudio, false); //play the call for units audio.

            foreach (Unit u in FactionEntity.FactionMgr.GetUnits())                  //go through the faction's units

            {
                if (currCapacity >= capacity) //if there are no longer free positions
                {
                    break;                    //stop
                }
                float distance = Vector3.Distance(transform.position, u.transform.position);

                //if the APC calls idle units only and the current unit is not idle or the APC doesn't call attack units and the current unit has an attack component
                if (CanAddUnit(u) == false || (callIdleOnly == true && u.IsIdle() == false) || (callAttackUnits == false && u.AttackComp != null))
                {
                    continue; //move to next unit in loop
                }
                //the target unit can't be another APC, it must be active, alive and inside the calling range
                if (u.APCComp == null && u.gameObject.activeInHierarchy == true && u.HealthComp.IsDead() == false && distance <= callUnitsRange)
                {
                    gameMgr.MvtMgr.Move(u, interactionPosition.position, 0.0f, FactionEntity, InputMode.APC, false); //move unit towards APC
                }
                //trigger custom event:
                CustomEvents.OnAPCCallUnit(this, u);
            }
        }