예제 #1
0
        //a method called to eject one unit locally
        public void EjectLocal(Unit unit, bool destroyed)
        {
            if (unit == null || storedUnits.Contains(unit) == false) //invalid unit or unit that's not stored here?
            {
                return;
            }

            unit.transform.position = GetInteractionPosition(); //set the unit position to the interaction position
            unit.transform.SetParent(null, true);               //APC is no longer the parent of the unit object
            storedUnits.Remove(unit);                           //remove unit from the list
            unit.gameObject.SetActive(true);                    //activate object

            unit.Interactable = true;                           //unit is no longer interactable since it's inside the APC.

            currCapacity -= unit.GetAPCSlots();                 //decrease the APC's current capacity

            AudioManager.Play(FactionEntity.AudioSourceComp, ejectUnitAudio, false);

            CustomEvents.OnAPCRemoveUnit(this, unit); //trigger custom event

            //if the APC is marked as destroyed and units are supposed to be destroyed as well
            if (destroyed == true && ejectOnDestroy == false)
            {
                unit.HealthComp.DestroyFactionEntity(false); //destroy unit
            }
        }