diff --git a/Assets/Scripts/Building.cs b/Assets/Scripts/Building.cs deleted file mode 100644 index 7a78c13..0000000 --- a/Assets/Scripts/Building.cs +++ /dev/null @@ -1,141 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class Building : MonoBehaviour -{ - [Header("Main-Info")] - [SerializeField] string Title = "Building"; - [SerializeField] string Description = "This is a building!"; - [SerializeField] int Level = 1; - [SerializeField] int Health = 100; - - - [Header("Build-Ressources")] - [SerializeField] int Wood = 0; - [SerializeField] int Stone = 0; - [SerializeField] int Clay = 0; - [SerializeField] int Straw = 0; - - [Header("Building")] - private Material oldMaterial; - private Color originalColor; - private bool isPlacingBuilding = false; - public int isColliding; - private new Renderer renderer; - - // Start is called before the first frame update - void Start() { - BuildingStart(); - - } - - // Update is called once per frame - void Update() { - BuildingUpdate(); - - } - - - public void BuildingStart() - { - renderer = GetComponent(); - originalColor = renderer.material.color; - } - public void BuildingUpdate() - { - if (!isPlacingBuilding) - { - renderer.material = oldMaterial; - isColliding = 0; - } - if (isColliding > 0) - { - changeMaterialToTransparent(renderer.material); - renderer.material.color = new Color(1, 0, 0, 0.3f); - } - else - { - if (isPlacingBuilding) - { - changeMaterialToTransparent(renderer.material); - renderer.material.color = new Color(0, 0, 1, 0.3f); - } - else - { - GetComponent().material.color = originalColor; - } - } - } - public void setTitle(string newTitle) { // Sets Title for building - Title = newTitle; - } - public string getTitle() { // Returns Title of building - return Title; - } - public void setDescription(string newDescription) { // Sets Description for building - Description = newDescription; - } - public string getDescription() { // Returns Description of building - return Description; - } - public void setHealth(int newHealth) { // Sets Health for building - Health = newHealth; - } - public int getHealth() { // Returns Health of building - return Health; - } - public void setLevel(int newLevel) { - Level = newLevel; - } - public int getLevel() { - return Level; - } - public bool delete() { - // if delete successfully return true else return false - return true; - } - - public void isPlacing(bool isCurrentlyPlacing) - { - if (isCurrentlyPlacing) - { - isPlacingBuilding = true; - return; - } - changeMaterialToOpaque(renderer.material); - renderer.material.color = new Color(1, 1, 1, 1); - isPlacingBuilding = false; - } - void OnCollisionEnter(Collision col) - { - isColliding += 1; - } - void OnCollisionExit(Collision col) - { - isColliding -= 1; - } - - void changeMaterialToOpaque(Material material) - { - material.SetOverrideTag("RenderType", ""); - material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); - material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); - material.SetInt("_ZWrite", 1); - material.DisableKeyword("_ALPHATEST_ON"); - material.DisableKeyword("_ALPHABLEND_ON"); - material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); - material.renderQueue = -1; - } - void changeMaterialToTransparent(Material material) - { - material.SetOverrideTag("RenderType", "Transparent"); - material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); - material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); - material.SetInt("_ZWrite", 0); - material.DisableKeyword("_ALPHATEST_ON"); - material.EnableKeyword("_ALPHABLEND_ON"); - material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); - material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; - } -} diff --git a/Assets/Scripts/Building.cs.meta b/Assets/Scripts/Building.cs.meta deleted file mode 100644 index 72e88e0..0000000 --- a/Assets/Scripts/Building.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 663feed4d05ec994fb1deb18b1767962 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Building/Building.cs.meta b/Assets/Scripts/Building/Building.cs.meta index 72e88e0..231dfdf 100644 --- a/Assets/Scripts/Building/Building.cs.meta +++ b/Assets/Scripts/Building/Building.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 663feed4d05ec994fb1deb18b1767962 +guid: 5c2ebc4f7d4eb064b814863e80d9bab0 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/BuildingPlacement.cs b/Assets/Scripts/BuildingPlacement.cs deleted file mode 100644 index 2421c2b..0000000 --- a/Assets/Scripts/BuildingPlacement.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class BuildingPlacement : MonoBehaviour -{ - TerrainCollider terrainCollider; - public GameObject terrain; - Ray ray; - public float rotation = 0; - [SerializeField] public GameObject building; - [SerializeField] bool isPlacing = false; - private Building currentBuilding; - - void Start() - { - currentBuilding = building.GetComponent(); - } - - void Update() - { - if (Input.GetButtonDown("Build")) { // Wenn man den Button 'B' - if (isPlacing) { // Wenn man 'B' zum zweiten mal dr�ckt - isPlacing = false; - currentBuilding.isColliding = 0; - currentBuilding.isPlacing(false); - building.SetActive(false); // Blueprint wird deaktiviert - } - else { // Wenn man zum ersten mal 'B' dr�ckt - building.SetActive(true); // Blueprint wird aktiviert - isPlacing = true; - } - } - if (building.transform != null && isPlacing) { - currentBuilding.isPlacing(true); - getRaycastMousePosition(); - rotateObject(); - if (Input.GetMouseButtonDown(0) && currentBuilding.isColliding == 0) { // Wenn es nicht Collidiert und man Links Klickt - isPlacing = false; - currentBuilding.isPlacing(false); - Instantiate(building, building.transform.position, building.transform.rotation); // Placed das Gebäude - building.SetActive(false); // Blueprint wird deaktiviert - } - } - } - - void getRaycastMousePosition() // Position of Mouse in World-Space - { - ray = Camera.main.ScreenPointToRay(Input.mousePosition); - RaycastHit hitData; - if (terrain.GetComponent().Raycast(ray, out hitData, Mathf.Infinity)) - { - building.transform.position = hitData.point; - } - } - void rotateObject() - { - if (Input.GetButtonDown("CounterRotate")) { // If Player presses button 'Left ALT' + 'R' - building.transform.Rotate(0, -10, 0); // Rotates the building counter clockwise - } - else if (Input.GetButtonDown("Rotate")) { // If Player presses button 'R' - building.transform.Rotate(0, 10, 0); // Rotates the building clockwise - } - } - -} diff --git a/Assets/Scripts/BuildingPlacement.cs.meta b/Assets/Scripts/BuildingPlacement.cs.meta deleted file mode 100644 index dc2dfa9..0000000 --- a/Assets/Scripts/BuildingPlacement.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: dcb2e348649dbce439cf77846fd11cd6 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: