Exemple #1
0
    public void UpdateUnit(Unit unit)   //returns true if succeeds, false otherwise
    //if (unit.speciesName != speciesName) { return; } //cant modify another species

    {
        if (!unit.CompareTag("Hostile"))
        {
            unit.UpdateHeadSize(headSize);
            unit.UpdateLegSize(legSize);
            unit.UpdateBellySize(bellySize);
            unit.UpdateEarSize(earSize);
            unit.UpdateTailSize(tailSize);
            unit.UpdateArmSize(armSize);
            unit.UpdateFurColor(color);
        }

        if (unit.CompareTag("Preview"))
        {
            return;
        }

        unit.genetiumSource    = genetiumSource;
        unit.foodSource        = foodSource;
        unit.speed             = speed;
        unit.interactionRadius = UnitHelperFunctions.Interpolate(legSize, new float[, ] {
            { 0.2f, 0.5f }, { 0.6f, 0.6f }
        });                                                                                                          //todo: rethink this

        //unit.areaCenter = areaCenter;


        //unit.areaRadius = AreaRadiusFromSize();
        unit.gameObject.tag = tag;
        unit.swimspeed      = swimspeed;

        if (tag == "Pet")
        {
            unit.enemyTag = "Hostile";
        }
        else if (tag == "Hostile")
        {
            unit.enemyTag = "Pet";
        }
        else
        {
            throw new System.Exception("Wrong tag for unit");
        }
        UnitActions.ResetSelectionGraphicPosition(unit);
        return;
    }
Exemple #2
0
    // null if not in range
    public static GameObject ClosestEnemyInRange(Unit unit)
    {
        //todo: redo using squared distance
        List <Unit> enemies;

        if (unit.enemyTag == "Hostile")
        {
            enemies = GameManager.gameManager.enemyList;
        }
        else
        {
            enemies = GameManager.gameManager.petList;
        }

        List <Unit>       aliveEnemies      = UnitHelperFunctions.FilterDeadEnemies(enemies);
        List <GameObject> enemiesGameObject = new List <GameObject>();

        foreach (var enemy in aliveEnemies)
        {
            enemiesGameObject.Add(enemy.gameObject);
        }
        //TODO: units should be taken out of the gameobject array juust when they die
        return(UnitHelperFunctions.GetClosest(unit, enemiesGameObject));
    }