From 65813a7b9d2b2be3a406e8b430322b24bed94375 Mon Sep 17 00:00:00 2001
From: Erno Lokkila <eolokk@utu.fi>
Date: Sun, 3 Mar 2019 23:51:16 +0200
Subject: [PATCH] win button hidden until enough money
---
Assets/Prefab/City.prefab | 10 ++++++++--
Assets/Scripts/City/City.cs | 8 ++++++--
Assets/Scripts/UI/BuyCity.cs | 6 +++++-
3 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/Assets/Prefab/City.prefab b/Assets/Prefab/City.prefab
index dfe9949..26076c5 100644
--- a/Assets/Prefab/City.prefab
+++ b/Assets/Prefab/City.prefab
@@ -71,7 +71,7 @@ SpriteRenderer:
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
- m_Sprite: {fileID: 21300000, guid: a69243cd6bee5c34497418b7bbea1e20, type: 3}
+ m_Sprite: {fileID: 21300000, guid: 4ffb6badf0a2c454c990a42fe64e9d03, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
@@ -99,7 +99,7 @@ BoxCollider2D:
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
- oldSize: {x: 1.28, y: 1.28}
+ oldSize: {x: 1, y: 1}
newSize: {x: 1.28, y: 1.28}
adaptiveTilingThreshold: 0.5
drawMode: 0
@@ -120,6 +120,12 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: f67208887d2c19940b9afdc55a275b38, type: 3}
m_Name:
m_EditorClassIdentifier:
+ sprites:
+ - {fileID: 21300000, guid: 4ffb6badf0a2c454c990a42fe64e9d03, type: 3}
+ - {fileID: 21300002, guid: 4ffb6badf0a2c454c990a42fe64e9d03, type: 3}
+ - {fileID: 21300004, guid: 4ffb6badf0a2c454c990a42fe64e9d03, type: 3}
+ - {fileID: 21300006, guid: 4ffb6badf0a2c454c990a42fe64e9d03, type: 3}
+ - {fileID: 21300008, guid: 4ffb6badf0a2c454c990a42fe64e9d03, type: 3}
respanelPrefab: {fileID: 3345454733487414898, guid: 588b79ebfef5a2c4887615dc4856cc0c,
type: 3}
resrowPrefab: {fileID: 5085001290068357248, guid: 72232997f27e3c2448b5ad647af22a35,
diff --git a/Assets/Scripts/City/City.cs b/Assets/Scripts/City/City.cs
index 3d541d5..3f62dd1 100644
--- a/Assets/Scripts/City/City.cs
+++ b/Assets/Scripts/City/City.cs
@@ -5,6 +5,10 @@ using UnityEngine;
public class City : MonoBehaviour
{
+ [SerializeField]
+ Sprite[] sprites;
+ private int spriteIndex = 0;
+
[SerializeField]
GameObject respanelPrefab;
@@ -104,7 +108,9 @@ public class City : MonoBehaviour
public void AddPopulation(int v)
{
+ spriteIndex = Math.Min(spriteIndex+1, sprites.Length-1);
this.population += v;
+ gameObject.GetComponent<SpriteRenderer>().sprite = sprites[spriteIndex];
}
private void Update()
@@ -179,7 +185,6 @@ public class City : MonoBehaviour
resurssit.RemoveAt(k);
}
- Debug.Log(poolit[j].GetAmount());
if (poolit[j].GetAmount() < amount)
{
return false;
@@ -187,7 +192,6 @@ public class City : MonoBehaviour
}
}
}
- Debug.Log(resurssit.Count);
return resurssit.Count == 0;
}
/**
diff --git a/Assets/Scripts/UI/BuyCity.cs b/Assets/Scripts/UI/BuyCity.cs
index e9c4980..9a093e3 100644
--- a/Assets/Scripts/UI/BuyCity.cs
+++ b/Assets/Scripts/UI/BuyCity.cs
@@ -11,7 +11,11 @@ public class BuyCity : MonoBehaviour
// Start is called before the first frame update
void Start()
{
-
+ if(!transform.root.gameObject.GetComponent<City>().IsSufficientResources(createResourceGO(), 150))
+ {
+ Color c = gameObject.GetComponent<SpriteRenderer>().color;
+ gameObject.GetComponent<SpriteRenderer>().color = c - new Color(25, 25, 25);
+ }
}
// Update is called once per frame
--
GitLab