IEnumerator MoveTowardsTheTarget() { for (;;) { int currentWeight = 1; //Default weight if (useWeightAsSpeed) { //Convert transform.position to Vector3Int Vector3Int vec = new Vector3Int((int)Math.Floor(transform.position.x), (int)Math.Floor(transform.position.y), (int)Math.Floor(transform.position.z)); TileBase playerTile = tilemap.GetTile(vec);//Get player current currentWeight = allowedTiles.GetWeight(playerTile); } timeBetweenSteps = 1 / (speed / currentWeight); yield return(new WaitForSeconds(timeBetweenSteps)); if (enabled && !atTarget) { MakeOneStepTowardsTheTarget(); } } }
private int GetWeight(TileBase neighborTile) { GameObject allowedObject = GameObject.Find("AllowedTiles"); AllowedTiles allowed = allowedObject.GetComponent <AllowedTiles>(); return(allowed.GetWeight(neighborTile)); }