Skip to content
Snippets Groups Projects
Commit b2ba3448 authored by Kimi Heinonen's avatar Kimi Heinonen
Browse files

resurisspalkit paivitetty

parent c764290b
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ GameObject:
- component: {fileID: 5007991825820669350}
- component: {fileID: 6445693634580716852}
m_Layer: 0
m_Name: Sand
m_Name: bar
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
......@@ -25,7 +25,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2308576596148104492}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 1.2059997, y: -0.10999938, z: 0}
m_LocalPosition: {x: 0.93, y: 0.291, z: 0}
m_LocalScale: {x: 0.70104766, y: 0.75656927, z: 1}
m_Children: []
m_Father: {fileID: 5761957582027681033}
......@@ -68,7 +68,7 @@ SpriteRenderer:
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: fe463401d3186b54086acff6bb82891f, type: 3}
m_Sprite: {fileID: 21300000, guid: 82eec913fc22f9043b7dd6a14b77fe77, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
......@@ -172,4 +172,10 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: bd508a1c9a5505c498ef74ef59a55518, type: 3}
m_Name:
m_EditorClassIdentifier:
icon: {fileID: 0}
sprites:
- {fileID: 21300000, guid: 82eec913fc22f9043b7dd6a14b77fe77, type: 3}
- {fileID: 21300002, guid: 82eec913fc22f9043b7dd6a14b77fe77, type: 3}
- {fileID: 21300004, guid: 82eec913fc22f9043b7dd6a14b77fe77, type: 3}
- {fileID: 21300006, guid: 82eec913fc22f9043b7dd6a14b77fe77, type: 3}
- {fileID: 21300008, guid: 82eec913fc22f9043b7dd6a14b77fe77, type: 3}
spriteR: {fileID: 0}
......@@ -116,7 +116,7 @@ public class City : MonoBehaviour
*/
public void AddResource(Resource r, int amount)
{
if (amount < 0)
if (r == null || amount < 0)
{
return;
}
......
......@@ -31,6 +31,10 @@ public class ResourcePool : MonoBehaviour
}
public void SetResource(Resource r)
{
if (r == null)
{
return;
}
this.r = r;
icon = r.getResourceImg();
}
......@@ -79,5 +83,9 @@ public class ResourcePool : MonoBehaviour
{
return this.maxCapacity;
}
public int GetAmount()
{
return amount;
}
}
......@@ -8,6 +8,10 @@ public class ResourceRow : MonoBehaviour
private Sprite sprite;
[SerializeField]
private Sprite[] sprites;
// Start is called before the first frame update
void Start()
{
......@@ -17,7 +21,7 @@ public class ResourceRow : MonoBehaviour
// Update is called once per frame
void Update()
{
UpdateBars();
}
public void SetRow(Resource r, float x, float y, float z)
......@@ -27,5 +31,38 @@ public class ResourceRow : MonoBehaviour
this.GetComponent<SpriteRenderer>().transform.position = new Vector3(x, y, z);
this.GetComponent<SpriteRenderer>().transform.localScale = new Vector3(0.35f, 0.35f, 1f);
}
public void UpdateBars()
{
GameObject city = GameObject.FindGameObjectWithTag("Home");
ResourcePool[] lista = city.GetComponents<ResourcePool>();
for (int i = 0; i < lista.Length; i++)
{
if (lista[i].GetResource().GetType().Equals(r.GetType()))
{
int amount = lista[i].GetAmount();
int max = lista[i].GetMaxCapacity();
float pros = amount*1f / max*1f;
if (pros<=0.2)
{
transform.GetChild(0).GetComponent<SpriteRenderer>().sprite = sprites[0];
} else if(pros<=0.4)
{
transform.GetChild(0).GetComponent<SpriteRenderer>().sprite = sprites[1];
} else if(pros<=0.6)
{
transform.GetChild(0).GetComponent<SpriteRenderer>().sprite = sprites[2];
} else if(pros<=0.8)
{
transform.GetChild(0).GetComponent<SpriteRenderer>().sprite = sprites[3];
} else
{
transform.GetChild(0).GetComponent<SpriteRenderer>().sprite = sprites[4];
}
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment