예제 #1
0
    public void updateGM()
    {
        if (!gm)
        {
            // if gameManager is not specified, do it
            gm = tile.transform.parent.GetComponent <GameManager>();
        }
        if (!thisUnitEnlisted)
        {
            // if unit has not been duplicated to UnitEnlisted state usable by gameManager, do it
            thisUnitEnlisted      = ScriptableObject.CreateInstance <UnitEnlisted>();
            thisUnitEnlisted.unit = this.gameObject;
            thisUnitEnlisted.updateData();

            // the main purpose of funcction: inform the gameManager
            // that this unit will act at this turn
            gm.units.Add(thisUnitEnlisted);
        }
    }
예제 #2
0
    void Update()
    {
        if ((upcomingTargets.Count > 0) && (movingAllowed))         // this code manages moves of the unit
        {
            if (beginNextMoving)
            {
                // set parameters of upcoming visual move
                startingPos  = transform.position;
                finishingPos = upcomingTargets[0].transform.position;
                startMove    = Time.time;
                stopMove     = Time.time + moveRate;

                // adjust new unit's placement
                transform.SetParent(upcomingTargets[0].transform);
                upcomingTargets[0].GetComponent <Tile>().unit = this.gameObject;
                setCoordinatesAndTile();

                // we should firstly wait for this movement to be finished
                beginNextMoving = false;

                //Debug.Log("Nailed it!");
            }

            // define our current visual position
            float a = ((Time.time - startMove) / (stopMove - startMove));
            transform.position = Vector3.Lerp(startingPos, finishingPos, a);

            // if we have arrived
            if (a >= 1)
            {
                //Debug.Log("Nailed it!!");
                //startingPos = transform.position;
                //upcomingTargets[0].GetComponent<Tile>().unit = null;

                // remove reached tile from our "to go" list
                upcomingTargets.RemoveAt(0);

                // if we have to go somewhere elsewhere
                if (upcomingTargets.Count > 0)
                {
                    // indicate that we are ready to go
                    beginNextMoving = true;

                    //Debug.Log("Nailed it!!!");
                }
                else
                {
                    // if our last tile from "to go" list is reached, then return booleans to "planning" mode
                    beginNextMoving = true;
                    movingAllowed   = false;

                    // delete copy of current unit
                    thisUnitEnlisted = null;

                    // send a note gameManager that we are done with this unit
                    gm.proceedNextUnit();

                    //Debug.Log("Nailed it!!!!");
                }
            }
        }
    }
예제 #3
0
 public static int compareByOrganisation(UnitEnlisted unit1, UnitEnlisted unit2)
 {
     return(unit2.organisation.CompareTo(unit1.organisation));
 }