From 6c4441f92ad5a008d8d987aa396cbf164a6dadf4 Mon Sep 17 00:00:00 2001 From: Petteri <jupean@utu.fi> Date: Sun, 3 Mar 2019 19:13:23 +0200 Subject: [PATCH] Collector change --- Assets/Prefab/Flag.prefab | 16 +++---- Assets/Prefab/StoneResouce.prefab | 27 +++++++++++ Assets/Scripts/Collector.cs | 51 +++++++++++---------- Assets/Sprites/Destination_pointer.png.meta | 31 ++++++------- 4 files changed, 76 insertions(+), 49 deletions(-) diff --git a/Assets/Prefab/Flag.prefab b/Assets/Prefab/Flag.prefab index ce84a5a..b701a51 100644 --- a/Assets/Prefab/Flag.prefab +++ b/Assets/Prefab/Flag.prefab @@ -27,8 +27,8 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8796312832300166883} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 4.078, y: 2.369, z: -1.0712891} - m_LocalScale: {x: 0.3136983, y: 0.3136983, z: 0.3136983} + m_LocalPosition: {x: 4.1858, y: 2.4768, z: -1.0712891} + m_LocalScale: {x: 0.48209155, y: 0.48209155, z: 0.48209155} m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 @@ -70,12 +70,12 @@ SpriteRenderer: m_SortingLayerID: 0 m_SortingLayer: 0 m_SortingOrder: 0 - m_Sprite: {fileID: 21300000, guid: dd3f1a90ef7844947ae3599531fcd6d2, type: 3} + m_Sprite: {fileID: 21300000, guid: 193b16b146586694db30d01f314707c1, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} m_FlipX: 0 m_FlipY: 0 m_DrawMode: 0 - m_Size: {x: 0.2, y: 0.2} + m_Size: {x: 1.28, y: 1.28} m_AdaptiveModeThreshold: 0.5 m_SpriteTileMode: 0 m_WasSpriteAssigned: 1 @@ -107,16 +107,16 @@ BoxCollider2D: m_IsTrigger: 1 m_UsedByEffector: 0 m_UsedByComposite: 0 - m_Offset: {x: 0, y: 0} + m_Offset: {x: 0.006986022, y: -0.04191205} m_SpriteTilingProperty: border: {x: 0, y: 0, z: 0, w: 0} pivot: {x: 0.5, y: 0.5} - oldSize: {x: 1.78, y: 1.44} - newSize: {x: 0.2, y: 0.2} + oldSize: {x: 1.28, y: 1.28} + newSize: {x: 1.28, y: 1.28} adaptiveTilingThreshold: 0.5 drawMode: 0 adaptiveTiling: 0 m_AutoTiling: 0 serializedVersion: 2 - m_Size: {x: 1.78, y: 1.44} + m_Size: {x: 1.3189669, y: 0.9649959} m_EdgeRadius: 0 diff --git a/Assets/Prefab/StoneResouce.prefab b/Assets/Prefab/StoneResouce.prefab index 82bfceb..e69bebe 100644 --- a/Assets/Prefab/StoneResouce.prefab +++ b/Assets/Prefab/StoneResouce.prefab @@ -11,6 +11,7 @@ GameObject: - component: {fileID: 4378544729630622907} - component: {fileID: 6537826622454043909} - component: {fileID: 4263803972273305565} + - component: {fileID: 6933693375278105387} m_Layer: 0 m_Name: StoneResouce m_TagString: Resource @@ -101,3 +102,29 @@ MonoBehaviour: - {fileID: 21300006, guid: 69185a3ed6e033642b69e02c07c3804c, type: 3} - {fileID: 21300008, guid: 69185a3ed6e033642b69e02c07c3804c, type: 3} - {fileID: 21300010, guid: 69185a3ed6e033642b69e02c07c3804c, type: 3} +--- !u!61 &6933693375278105387 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6392040089189307514} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0, y: 0} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0.5, y: 0.5} + oldSize: {x: 1, y: 1} + newSize: {x: 1, y: 1} + adaptiveTilingThreshold: 0.5 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + serializedVersion: 2 + m_Size: {x: 1, y: 1} + m_EdgeRadius: 0 diff --git a/Assets/Scripts/Collector.cs b/Assets/Scripts/Collector.cs index dbce85f..94e742b 100644 --- a/Assets/Scripts/Collector.cs +++ b/Assets/Scripts/Collector.cs @@ -80,9 +80,7 @@ public class Collector : MonoBehaviour RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero); if (hit.collider != null) { - if (hit.collider.gameObject.tag == "Home") - home.gameObject.GetComponent<City>().AddCollector(); - if (hit.collider.gameObject.GetComponent<Outcrop>() != null) + if (hit.collider.gameObject.GetComponent<Outcrop>() != null && hit.collider.gameObject.tag == "Buildable") { this.send_to_resource = true; } @@ -106,18 +104,19 @@ public class Collector : MonoBehaviour if (target_flag != null) { - if(collision.gameObject.transform.position == target_flag.transform.position) { + if(collision.gameObject.transform.position == target_flag.transform.position) + { if(resource == null) { 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>()) + else if (send_to_resource && target.GetComponent<Outcrop>() && target.tag == "Buildable") { if(this.amount > 0) - target.GetComponent<Outcrop>().setAmount(this.amount); - //Requested_resource = target.GetComponent<Outcrop>(); + target.GetComponent<Outcrop>().addResource(this.amount); + Requested_resource = target.GetComponent<Outcrop>().getNeededResource(); Requested_amount = target.GetComponent<Outcrop>().stillNeeded(); StartCoroutine("goHome"); } @@ -130,30 +129,36 @@ public class Collector : MonoBehaviour StartCoroutine("goHome"); } - + } else + { StartCoroutine("goHome"); - } - } - if (move_to.gameObject.tag == "Home" && this.resource != null) - { - if (target.GetComponent<Outcrop>()) - { - /*if(this.Requested_amount < this.max_amount) - this.amount = home.GetComponent<City>().UseResource(, this.Requested_amount); - else - this.amount = home.GetComponent<City>().UseResource(, this.max_amount);*/ + } } else { + if (collision.gameObject.GetComponent<BoxCollider2D>().bounds.Contains(new Vector3(home.transform.position.x, home.transform.position.y, collision.gameObject.transform.position.z))) + { + if (target.GetComponent<Outcrop>() && this.Requested_resource != null) + { + if(this.Requested_amount < this.max_amount) + this.amount = home.GetComponent<City>().UseResource(this.Requested_resource, this.Requested_amount); + else + this.amount = home.GetComponent<City>().UseResource(this.Requested_resource, this.max_amount); + } + else + { + + //resets amount and resource variables + collision.gameObject.GetComponent<City>().AddResource(this.resource, this.amount); + this.amount = 0; + this.resource = null; + } - //resets amount and resource variables - collision.gameObject.GetComponent<City>().AddResource(this.resource, this.amount); - this.amount = 0; - this.resource = null; + MoveTo(this.target); + } } - MoveTo(this.target); } } IEnumerator goHome() diff --git a/Assets/Sprites/Destination_pointer.png.meta b/Assets/Sprites/Destination_pointer.png.meta index 4b8e672..d3b6b03 100644 --- a/Assets/Sprites/Destination_pointer.png.meta +++ b/Assets/Sprites/Destination_pointer.png.meta @@ -1,13 +1,5 @@ fileFormatVersion: 2 -<<<<<<< HEAD guid: 193b16b146586694db30d01f314707c1 -======= -<<<<<<< HEAD -guid: 5f1dd03bd2b18f74f8bdf8a7643e95cd -======= -guid: d3c9bafef3c25ef48b06b098ee1e0d12 ->>>>>>> f671c3e28cd26c667fb91d7dd0a7069ea183ba1b ->>>>>>> 26ce5a29592f8304c4bcd6a6414c9c688c665a12 TextureImporter: fileIDToRecycleName: {} externalObjects: {} @@ -44,7 +36,7 @@ TextureImporter: mipBias: -100 wrapU: 1 wrapV: 1 - wrapW: 1 + wrapW: -1 nPOTScale: 0 lightmap: 0 compressionQuality: 50 @@ -77,21 +69,24 @@ TextureImporter: allowsAlphaSplitting: 0 overridden: 0 androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 spriteSheet: serializedVersion: 2 sprites: [] outline: [] physicsShape: [] bones: [] -<<<<<<< HEAD - spriteID: 0aa1fc7d41d52094ab7dc406bfc9045d -======= -<<<<<<< HEAD - spriteID: 7bd4f1e7ac076824889ec633e10e0ca8 -======= - spriteID: 5a0b38d14e376af42b2ac4c7cab18d7a ->>>>>>> f671c3e28cd26c667fb91d7dd0a7069ea183ba1b ->>>>>>> 26ce5a29592f8304c4bcd6a6414c9c688c665a12 + spriteID: vertices: [] indices: edges: [] -- GitLab