From 7345c34537e1ddb0fe681f8b344d3d7d22d81452 Mon Sep 17 00:00:00 2001 From: DerTyp187 Date: Fri, 1 Oct 2021 21:28:28 +0200 Subject: [PATCH] Clean Up --- Assets/Scenes/SampleScene.unity | 8 +- Assets/Scripts/Building/BuildingBlueprint.cs | 107 ++++++++++--------- ProjectSettings/InputManager.asset | 4 +- ProjectSettings/TagManager.asset | 1 + 4 files changed, 64 insertions(+), 56 deletions(-) diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index ced1a44..8b84ca7 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -580,7 +580,7 @@ GameObject: - component: {fileID: 708126141} - component: {fileID: 708126140} m_Layer: 5 - m_Name: Canvas + m_Name: HUD m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -1676,7 +1676,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} propertyPath: jumpForce - value: 3.5 + value: 4 objectReference: {fileID: 0} - target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3} propertyPath: jumpHeight @@ -1710,6 +1710,10 @@ PrefabInstance: propertyPath: m_Name value: FirstPerson Player objectReference: {fileID: 0} + - target: {fileID: 8390537188327133021, guid: 6a86db7765f277243b912c20f451dc47, type: 3} + propertyPath: m_TagString + value: FPSPlayer + objectReference: {fileID: 0} - target: {fileID: 8390537188327133022, guid: 6a86db7765f277243b912c20f451dc47, type: 3} propertyPath: m_RootOrder value: 1 diff --git a/Assets/Scripts/Building/BuildingBlueprint.cs b/Assets/Scripts/Building/BuildingBlueprint.cs index 3cc2025..394b10a 100644 --- a/Assets/Scripts/Building/BuildingBlueprint.cs +++ b/Assets/Scripts/Building/BuildingBlueprint.cs @@ -5,7 +5,6 @@ using UnityEngine; public abstract class BuildingBlueprint : MonoBehaviour { public bool isColliding; - public bool followMouse = true; public GameObject constructionPrefab; private GameObject terrain; @@ -20,67 +19,31 @@ public abstract class BuildingBlueprint : MonoBehaviour private void Start() { - hud = GameObject.Find("HUD").GetComponent(); + hud = GameObject.Find("HUD").GetComponent(); //Get HUD Canvas + terrain = GameObject.FindGameObjectWithTag("Terrain"); //Get Terrain //Bug Fix Blueprints already existing + //Delete/CleanUp all objs with tag "Blueprint" GameObject[] blueprints = GameObject.FindGameObjectsWithTag("Blueprint"); - foreach (GameObject blueprint in blueprints) Destroy(blueprint); - gameObject.tag = "Blueprint"; + gameObject.tag = "Blueprint"; //Give Gameobject the tag "Blueprint" (after deleting all objs with this tag) - terrain = GameObject.FindGameObjectWithTag("Terrain"); - - hud.enabled = false; + hud.enabled = false; //Hide HUD - Init(); + Init(); //Call init callback function for children } - - //Collision - public void OnCollisionEnter(Collision collision) - { - isColliding = true; - - Debug.Log("Colliding True"); - } - public void OnCollisionStay(Collision collision) - { - isColliding = true; - Debug.Log("Colliding True"); - } - public void OnCollisionExit(Collision collision) - { - isColliding = false; - Debug.Log("Colliding False"); - } - - //Placing public void Update() { - if (followMouse) - { - //Following Mouse - ray = Camera.main.ScreenPointToRay(Input.mousePosition); - RaycastHit hitData; - if (terrain.GetComponent().Raycast(ray, out hitData, Mathf.Infinity)) - { - transform.position = hitData.point; - } - } - - if (Input.GetMouseButtonDown(0) && !isColliding) - { - Instantiate(constructionPrefab, transform.position, transform.rotation); - Destroy(this.gameObject); - hud.enabled = true; - } + FollowMouse(); + Rotate(); //Collinding Callbacks if (isColliding) - { + { WhileColliding(); } else @@ -88,15 +51,32 @@ public abstract class BuildingBlueprint : MonoBehaviour WhileNotColliding(); } + //PLACE + if (Input.GetMouseButtonDown(0) && !isColliding) + { + Place(); + } + } - //Rotate + void FollowMouse() + { + ray = Camera.main.ScreenPointToRay(Input.mousePosition); + RaycastHit hitData; + if (terrain.GetComponent().Raycast(ray, out hitData, Mathf.Infinity)) + { + transform.position = hitData.point; + } + } + void Rotate() + { if (Input.GetButtonDown("Rotate")) { Debug.Log("Rotate+"); if (Input.GetKey(KeyCode.LeftShift)) { transform.Rotate(0, 5, 0); - }else if (Input.GetKey(KeyCode.LeftControl)) + } + else if (Input.GetKey(KeyCode.LeftControl)) { transform.Rotate(0, 45, 0); } @@ -104,7 +84,7 @@ public abstract class BuildingBlueprint : MonoBehaviour { transform.Rotate(0, 22.5f, 0); } - + } if (Input.GetButtonDown("CounterRotate")) @@ -113,7 +93,8 @@ public abstract class BuildingBlueprint : MonoBehaviour if (Input.GetKey(KeyCode.LeftShift)) { transform.Rotate(0, -5, 0); - }else if (Input.GetKey(KeyCode.LeftControl)) + } + else if (Input.GetKey(KeyCode.LeftControl)) { transform.Rotate(0, -45, 0); } @@ -123,8 +104,30 @@ public abstract class BuildingBlueprint : MonoBehaviour } } - - + } + void Place() + { + Instantiate(constructionPrefab, transform.position, transform.rotation); + Destroy(this.gameObject); + hud.enabled = true; } + + //Collision + public void OnCollisionEnter(Collision c) + { + isColliding = true; + + Debug.Log("Colliding True"); + } + public void OnCollisionStay(Collision c) + { + isColliding = true; + Debug.Log("Colliding True"); + } + public void OnCollisionExit(Collision c) + { + isColliding = false; + Debug.Log("Colliding False"); + } } diff --git a/ProjectSettings/InputManager.asset b/ProjectSettings/InputManager.asset index 24f8951..0f08b43 100644 --- a/ProjectSettings/InputManager.asset +++ b/ProjectSettings/InputManager.asset @@ -362,7 +362,7 @@ InputManager: descriptiveName: descriptiveNegativeName: negativeButton: - positiveButton: r + positiveButton: x altNegativeButton: altPositiveButton: gravity: 1000 @@ -378,7 +378,7 @@ InputManager: descriptiveName: descriptiveNegativeName: negativeButton: - positiveButton: q + positiveButton: y altNegativeButton: altPositiveButton: gravity: 1000 diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index b388863..2e73064 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -10,6 +10,7 @@ TagManager: - Terrain - Blueprint - StorageBuilding + - FPSPlayer layers: - Default - TransparentFX