// Update is called once per frame void Update() { if (isDead) { //despawnTimer += Time.deltaTime; //if (despawnTimer > Despawn) //{ // Destroy(gameObject); //} return; } // somehow check if you are at the jobsite and once done remove the job if (IsIdle) { JobDispatcher availableJobs = Fire.Jobs; if (availableJobs.HasJobs()) { JobDispatcher.Job job = availableJobs.GetNearestJob(TilePosition()); TakeJob(job); AtJobSite = false; } else { // TODO look for next fire pathFollowing.MoveToRandomLocationInSquare(); Fire fire = World.Get().GetNearestFireWithJobs(new Vector2(gameObject.transform.position.x, gameObject.transform.position.y)); if (fire != null) { if (Fire.NumAssociatedWorkers() > 5) { Fire.WorkerLeaving(gameObject); Fire = fire; Fire.WorkerComing(gameObject); } } } } else { if (Job.Coordinates == TilePosition()) { pathFollowing.CurrentPath.Cancel(); if (Job.IsReady()) { JobProgress += Time.deltaTime; gameObject.GetComponent <Animator>().SetBool("isChopping", true); } else if (!AtJobSite) { AtJobSite = true; Job.Arrived(); } if (JobProgress >= Job.Duration()) { gameObject.GetComponent <Animator>().SetBool("isChopping", false); Debug.Log("Changing Tile of Type " + World.Get().Tiles[Job.Coordinates].TileType.ToString()); if (Job.JobType == JobDispatcher.Job.Type.Chop) { World.Get().ChoppedTree(Job.Coordinates); } else { Fire fire = World.Get().SpawnCampFire(World.Get().GetWorldLocation(Job.Coordinates)); if (fire != null) { Fire = fire; } } JobProgress = 0f; Job = null; IsIdle = true; } } } if (Fire.CurrentBurnRate == 0) { deathTimer += Time.deltaTime; if (deathTimer > SecondsToDeath) { gameObject.GetComponent <Animator>().SetBool("isDead", true); World.Get().RemoveWorker(gameObject); isDead = true; } } else { deathTimer = 0f; } }