Exemplo n.º 1
0
        //move one single unit to a destination
        public void MoveLocal(Unit RefUnit, Vector3 Destination, float CircleRadius, GameObject TargetObj, InputTargetMode TargetMode)
        {
            if (RefUnit.CanBeMoved == true) //making sure the unit can be moved
            {
                Destination = new Vector3(Destination.x, TerrainMgr.SampleHeight(Destination), Destination.z);
                Vector3 MvtPos = Vector3.zero;

                //Make the ref unit's target collider pos so it won't be detected as invalid destination
                RefUnit.TargetPosColl.isTrigger = false;

                //trigger if we can move directly to the chosen destination (assuming that there's no target object to move to).
                if (IsDestinationClear(Destination, RefUnit, out MvtPos) && TargetObj == null)
                {
                    RefUnit.CheckUnitPathLocal(MvtPos, null, Destination, MvtStoppingDistance, InputTargetMode.None);
                }
                else
                {
                    //the positions that the units will fill
                    List <Vector3> Positions = CircleFormation(Destination, CircleRadius, RefUnit);

                    //get a valid position for the unit to move to
                    while (Positions.Count == 0)
                    {
                        Positions     = CircleFormation(Destination, CircleRadius, RefUnit);
                        CircleRadius += RefUnit.NavAgent.radius;
                    }

                    RefUnit.CheckUnitPathLocal(Positions[GetClosestPosID(Positions, RefUnit.transform.position)], TargetObj, Destination, MvtStoppingDistance, TargetMode);
                }

                //trigger the ref unit's target collider pos so it will be detected again:
                RefUnit.TargetPosColl.isTrigger = true;
            }
            else if (RefUnit.FactionID == GameManager.PlayerFactionID) //if the unit that can't be moved belongs to the local player's faction
            {
                UIMgr.ShowPlayerMessage("Can't move selected unit!", UIManager.MessageTypes.Error);
            }

            if (GameMgr.Events)
            {
                GameMgr.Events.OnUnitMoveAttempt(RefUnit); //custom event call
            }
        }
Exemplo n.º 2
0
 //a method to get the spawn position for newly created units:
 public Vector3 GetSpawnPosition()
 {
     if (TaskHolder == TaskHolders.Building)                                                                                                                           //if the task holder is a building
     {
         return(new Vector3(RefBuilding.SpawnPosition.position.x, TerrainMgr.SampleHeight(RefBuilding.SpawnPosition.position), RefBuilding.SpawnPosition.position.z)); //return the building's assigned spawn position
     }
     else //if this is a unit
     {
         return(transform.position); //return the unit's position
     }
 }