mirror of
https://github.com/DerTyp7/fps-citybuild-unity.git
synced 2025-10-29 12:22:07 +01:00
Bug Fixes
This commit is contained in:
@@ -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<Renderer>();
|
||||
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<Renderer>().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;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 663feed4d05ec994fb1deb18b1767962
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 663feed4d05ec994fb1deb18b1767962
|
||||
guid: 5c2ebc4f7d4eb064b814863e80d9bab0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
||||
@@ -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<Building>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetButtonDown("Build")) { // Wenn man den Button 'B'
|
||||
if (isPlacing) { // Wenn man 'B' zum zweiten mal dr<64>ckt
|
||||
isPlacing = false;
|
||||
currentBuilding.isColliding = 0;
|
||||
currentBuilding.isPlacing(false);
|
||||
building.SetActive(false); // Blueprint wird deaktiviert
|
||||
}
|
||||
else { // Wenn man zum ersten mal 'B' dr<64>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<Collider>().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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcb2e348649dbce439cf77846fd11cd6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user