Exemplo n.º 1
0
    public GameObject SpawnWorker(Fire fire, bool randomize = true)
    {
        if (Workers.Count > generationParameters.resources.workerCapPerFire * Fires.Count)
        {
            return(null);
        }
        // This order by with weighed random will shuffle the list but segregate the shuffle grass tiled as more important than the others
        Vector2Int pos = Vector2Int.zero;

        try
        {
            pos = fire.GetInfluence().OrderBy(t => Random.value * (t.TileType == Tile.Type.Grass ? 1f : 10f)).ToList().Find(t => t.TileType == Tile.Type.Grass || t.TileType == Tile.Type.Tree).Coordinates;
        }
        catch
        {
            pos = fire.TilePosition();
        }
        GameObject worker = Instantiate <GameObject>(workerPrefabs[Random.Range(0, workerPrefabs.Length)], GetWorldLocation(pos), Quaternion.identity);

        Workers.Add(worker);
        AgentJobHandler jobsScript = worker.GetComponent <AgentJobHandler>();

        if (jobsScript == null)
        {
            Debug.LogError("Worker had no job handler?!");
            return(null);
        }
        jobsScript.Fire = fire;
        return(worker);
    }
Exemplo n.º 2
0
    void Update()
    {
        AgentJobHandler jobHandler = GetComponent <AgentJobHandler>();

        if (jobHandler && jobHandler.isDead)
        {
            return;
        }
        if (AccumulatedInput.SqrMagnitude() > 0)
        {
            animator.SetBool("isWalking", true);
        }
        else
        {
            animator.SetBool("isWalking", false);
        }
        HandleInput();
        HandleTranslation();
    }