Example #1
0
    private IEnumerator SpawnAndMove()
    {
        turnController.AddSpawner();

        Unit newUnit = SpawnUnit();

        if (doorHex != null && targetHex != null)
        {
            // Check if here is a unit at the target hex, if so get a new target around it
            if (targetHex.CurrentUnit != null)
            {
                targetHex = targetHex.GetNeighbour(HexUtility.VecToHexDirection(currentHex.transform.position - targetHex.transform.position));
            }

            newUnit.WalkDirectlyToTile(doorHex, targetHex);

            yield return(new WaitUntil(() => newUnit.IsPerformingAction == false));

            float distanceToEarth     = Vector3.Distance(currentHex.transform.position, Manager.instance.PlayerController.EarthUnit.CurrentTile.transform.position);
            float distanceToLightning = Vector3.Distance(currentHex.transform.position, Manager.instance.PlayerController.LightningUnit.CurrentTile.transform.position);
            Hex   closestPlayerTile   = distanceToEarth < distanceToLightning ? Manager.instance.PlayerController.EarthUnit.CurrentTile : Manager.instance.PlayerController.LightningUnit.CurrentTile;

            newUnit.WalkDirectlyToTile(targetHex, closestPlayerTile);

            yield return(new WaitUntil(() => newUnit.IsPerformingAction == false));
        }
        else
        {
            float distanceToEarth     = Vector3.Distance(currentHex.transform.position, Manager.instance.PlayerController.EarthUnit.CurrentTile.transform.position);
            float distanceToLightning = Vector3.Distance(currentHex.transform.position, Manager.instance.PlayerController.LightningUnit.CurrentTile.transform.position);
            Hex   closestPlayerTile   = distanceToEarth <= distanceToLightning ? Manager.instance.PlayerController.EarthUnit.CurrentTile : Manager.instance.PlayerController.LightningUnit.CurrentTile;

            newUnit.RotateTo(closestPlayerTile.transform.position);
        }

        turnController.RemoveSpawner();

        //doneSpawning = true;
    }