Skip to content
Snippets Groups Projects
Commit 4d8259c2 authored by Petteri's avatar Petteri
Browse files

collectore update and ground generator change

changed ground generators collector creation to use city add collector method
parent da94e61c
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,15 @@ public class Collector : MonoBehaviour ...@@ -13,6 +13,15 @@ public class Collector : MonoBehaviour
[SerializeField] [SerializeField]
private int max_amount = 10; private int max_amount = 10;
[SerializeField]
private int Requested_amount;
[SerializeField]
private Resource Requested_resource;
[SerializeField]
private bool OnkoVapaa;
[SerializeField] [SerializeField]
private int amount; private int amount;
...@@ -26,6 +35,8 @@ public class Collector : MonoBehaviour ...@@ -26,6 +35,8 @@ public class Collector : MonoBehaviour
[SerializeField] [SerializeField]
private GameObject target_flag; private GameObject target_flag;
[SerializeField]
private bool send_to_resource;
public GameObject flag; public GameObject flag;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
...@@ -33,6 +44,14 @@ public class Collector : MonoBehaviour ...@@ -33,6 +44,14 @@ public class Collector : MonoBehaviour
home = GameObject.FindGameObjectWithTag("Home"); home = GameObject.FindGameObjectWithTag("Home");
} }
public void SetOnkoVapaa(bool vapaa)
{
this.OnkoVapaa = vapaa;
}
public bool tarkistaVapaus()
{
return this.OnkoVapaa;
}
public void SetTarget(GameObject target) public void SetTarget(GameObject target)
{ {
this.target = target; this.target = target;
...@@ -41,10 +60,18 @@ public class Collector : MonoBehaviour ...@@ -41,10 +60,18 @@ public class Collector : MonoBehaviour
{ {
this.move_to = target; this.move_to = target;
} }
public Resource getResource()
{
return this.resource;
}
public void SetSend_to_resource(bool r)
{
this.send_to_resource = r;
}
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
if (Input.GetMouseButtonDown(0)) if (Input.GetMouseButtonDown(0))
{ {
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
...@@ -53,6 +80,16 @@ public class Collector : MonoBehaviour ...@@ -53,6 +80,16 @@ public class Collector : MonoBehaviour
RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero); RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero);
if (hit.collider != null) if (hit.collider != null)
{ {
if (hit.collider.gameObject.tag == "Home")
home.gameObject.GetComponent<City>().AddCollector();
if (hit.collider.gameObject.GetComponent<Outcrop>() != null)
{
this.send_to_resource = true;
}
else
{
this.send_to_resource = false;
}
DestroyImmediate(target_flag); DestroyImmediate(target_flag);
target_flag = Instantiate(flag, hit.point, Quaternion.identity); target_flag = Instantiate(flag, hit.point, Quaternion.identity);
target_flag.GetComponent<Flag>().SetWorker(this.gameObject); target_flag.GetComponent<Flag>().SetWorker(this.gameObject);
...@@ -72,30 +109,51 @@ public class Collector : MonoBehaviour ...@@ -72,30 +109,51 @@ public class Collector : MonoBehaviour
if(collision.gameObject.transform.position == target_flag.transform.position) { if(collision.gameObject.transform.position == target_flag.transform.position) {
if(resource == null) if(resource == null)
{ {
/*if(target.GetComponent<Resource>().vie_tavaraa()) if(home.GetComponent<BoxCollider2D>().bounds.Contains(new Vector3(target_flag.transform.position.x, target_flag.transform.position.y,home.transform.position.z)))
{ {
Destroy(target_flag);
}
else if (send_to_resource && target.GetComponent<Outcrop>())
{
if(this.amount > 0)
target.GetComponent<Outcrop>().setAmount(this.amount);
//Requested_resource = target.GetComponent<Outcrop>();
Requested_amount = target.GetComponent<Outcrop>().stillNeeded();
StartCoroutine("goHome");
} }
else else
{*/ {
//Amount of resources worker is carrying right now //Amount of resources worker is carrying right now
this.amount = target.GetComponent<Resource>().extractResource(this.max_amount); this.amount = target.GetComponent<Resource>().extractResource(this.max_amount);
//Gives target resource to resource variable //Gives target resource to resource variable
this.resource = this.target.GetComponent<Resource>(); this.resource = this.target.GetComponent<Resource>();
//} StartCoroutine("goHome");
}
} }
StartCoroutine("goHome"); else
StartCoroutine("goHome");
} }
} }
if (collision.gameObject.tag == "Home" && this.resource != null) if (move_to.gameObject.tag == "Home" && this.resource != null)
{ {
//resets amount and resource variables if (target.GetComponent<Outcrop>())
collision.gameObject.GetComponent<City>().AddResource(this.resource, this.amount); {
this.amount = 0; /*if(this.Requested_amount < this.max_amount)
this.resource = null; this.amount = home.GetComponent<City>().UseResource(, this.Requested_amount);
MoveTo(this.target); else
this.amount = home.GetComponent<City>().UseResource(, this.max_amount);*/
}
else
{
//resets amount and resource variables
collision.gameObject.GetComponent<City>().AddResource(this.resource, this.amount);
this.amount = 0;
this.resource = null;
}
MoveTo(this.target);
} }
} }
IEnumerator goHome() IEnumerator goHome()
......
...@@ -151,7 +151,7 @@ public class GroundGenerator : MonoBehaviour ...@@ -151,7 +151,7 @@ public class GroundGenerator : MonoBehaviour
private void createHome() { private void createHome() {
ground[ground.GetLength(0) / 2, ground.GetLength(1) / 2] = home; ground[ground.GetLength(0) / 2, ground.GetLength(1) / 2] = home;
spawn(homeGO, houseCoords[0], houseCoords[1], houseDepth); spawn(homeGO, houseCoords[0], houseCoords[1], houseDepth);
spawn(workerGO, houseCoords[0], houseCoords[1], workerDepth); homeGO.GetComponent<City>().AddCollector();
} }
private GameObject spawn(GameObject go, int x, int y, int z) { private GameObject spawn(GameObject go, int x, int y, int z) {
return Instantiate<GameObject>(go, new Vector3(x, y, z), Quaternion.identity); return Instantiate<GameObject>(go, new Vector3(x, y, z), Quaternion.identity);
......
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