mirror of
				https://github.com/DerTyp7/fps-citybuild-unity.git
				synced 2025-10-31 05:07:08 +01:00 
			
		
		
		
	Merge branch 'NPC' of https://github.com/DerTyp187/fps-citybuild into NPC
This commit is contained in:
		| @@ -5,11 +5,10 @@ using UnityEngine; | ||||
| public abstract class BuildingBlueprint : MonoBehaviour | ||||
| { | ||||
|     public bool isColliding; | ||||
|     public bool followMouse = true; | ||||
|     public GameObject constructionPrefab; | ||||
|      | ||||
|     private GameObject terrain; | ||||
|  | ||||
|     private Canvas hud; | ||||
|  | ||||
|     Ray ray; | ||||
|  | ||||
| @@ -20,63 +19,115 @@ public abstract class BuildingBlueprint : MonoBehaviour | ||||
|  | ||||
|     private void Start() | ||||
|     { | ||||
|         hud = GameObject.Find("HUD").GetComponent<Canvas>(); //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) | ||||
|         GameObject.Destroy(blueprint); | ||||
|             Destroy(blueprint); | ||||
|  | ||||
|         gameObject.tag = "Blueprint"; | ||||
|    | ||||
|         gameObject.tag = "Blueprint"; //Give Gameobject the tag "Blueprint" (after deleting all objs with this tag) | ||||
|  | ||||
|         terrain = GameObject.FindGameObjectWithTag("Terrain"); | ||||
|         Init(); | ||||
|         hud.enabled = false; //Hide HUD | ||||
|  | ||||
|         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<Collider>().Raycast(ray, out hitData, Mathf.Infinity)) | ||||
|             { | ||||
|                 transform.position = hitData.point; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         if (Input.GetMouseButtonDown(0) && !isColliding) | ||||
|         { | ||||
|             Instantiate(constructionPrefab, transform.position, transform.rotation); | ||||
|             Destroy(this.gameObject); | ||||
|         } | ||||
|         FollowMouse(); | ||||
|         Rotate(); | ||||
|  | ||||
|         //Collinding Callbacks | ||||
|         if (isColliding) | ||||
|         { | ||||
|         {             | ||||
|             WhileColliding(); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             WhileNotColliding(); | ||||
|         } | ||||
|  | ||||
|         //PLACE | ||||
|         if (Input.GetMouseButtonDown(0) && !isColliding) | ||||
|         { | ||||
|             Place(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     void FollowMouse() | ||||
|     { | ||||
|         ray = Camera.main.ScreenPointToRay(Input.mousePosition); | ||||
|         RaycastHit hitData; | ||||
|         if (terrain.GetComponent<Collider>().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)) | ||||
|             { | ||||
|                 transform.Rotate(0, 45, 0); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 transform.Rotate(0, 22.5f, 0); | ||||
|             } | ||||
|  | ||||
|         } | ||||
|  | ||||
|         if (Input.GetButtonDown("CounterRotate")) | ||||
|         { | ||||
|             Debug.Log("Rotate-"); | ||||
|             if (Input.GetKey(KeyCode.LeftShift)) | ||||
|             { | ||||
|                 transform.Rotate(0, -5, 0); | ||||
|             } | ||||
|             else if (Input.GetKey(KeyCode.LeftControl)) | ||||
|             { | ||||
|                 transform.Rotate(0, -45, 0); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 transform.Rotate(0, -22.5f, 0); | ||||
|             } | ||||
|  | ||||
|         } | ||||
|     } | ||||
|     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"); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -14,15 +14,12 @@ public class HouseConstruction : BuildingConstruction | ||||
|  | ||||
|     public override void Init() | ||||
|     { | ||||
|         gameManager = GameObject.Find("GameManager"); | ||||
|         gameManager.GetComponent<EventLog>().CreateEvent("Construction: House"); | ||||
|     } | ||||
|  | ||||
|     public override bool CheckForResources() | ||||
|     { | ||||
|         if (havingWood == neededWood) | ||||
|         { | ||||
|             gameManager.GetComponent<EventLog>().CreateEvent("Construction: House: finished"); | ||||
|             return true; | ||||
|         } | ||||
|         return false; | ||||
|   | ||||
| @@ -30,6 +30,8 @@ public class PlayerMovement : MonoBehaviour | ||||
|  | ||||
|     Vector3 movement; | ||||
|  | ||||
|     | ||||
|  | ||||
|     private void Start() | ||||
|     { | ||||
|         rb = GetComponent<Rigidbody>(); | ||||
|   | ||||
| @@ -1,78 +0,0 @@ | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
|  | ||||
| public class EventLog : MonoBehaviour | ||||
| { | ||||
|     [Header("Event Log")] | ||||
|     [SerializeField] private GameObject eventObject; | ||||
|     [SerializeField] private Transform parentEventObject; | ||||
|     Vector3 position = new Vector3 (Screen.width-200, 134f, 0f); | ||||
|     [SerializeField] GameObject[] events; | ||||
|     void Start() | ||||
|     { | ||||
|          | ||||
|  | ||||
|     } | ||||
|  | ||||
|     // Update is called once per frame | ||||
|     void Update() | ||||
|     { | ||||
|         events = GameObject.FindGameObjectsWithTag("Event"); | ||||
|         if(events.Length <= 4) | ||||
|         { | ||||
|             switch (events.Length) | ||||
|             { | ||||
|                 case 0: | ||||
|                     position.y = 134f; | ||||
|                     break; | ||||
|                 case 1: | ||||
|                     position.y = 174f; | ||||
|                     break; | ||||
|                 case 2: | ||||
|                     position.y = 214f; | ||||
|                     break; | ||||
|                 case 3: | ||||
|                     position.y = 254f; | ||||
|                     break; | ||||
|             } | ||||
|  | ||||
|             //Relocate | ||||
|  | ||||
|             for (int i = 0; i < events.Length; i++) | ||||
|             { | ||||
|                 switch (events.Length) | ||||
|                 { | ||||
|                     case 1: | ||||
|                         events[0].transform.position = new Vector3(Screen.width - 200, 134f, 0f); | ||||
|                         break; | ||||
|                     case 2: | ||||
|                         events[0].transform.position = new Vector3(Screen.width - 200, 134f, 0f); | ||||
|                         events[1].transform.position = new Vector3(Screen.width - 200, 174f, 0f); | ||||
|                         break; | ||||
|                     case 3: | ||||
|                         events[0].transform.position = new Vector3(Screen.width - 200, 134f, 0f); | ||||
|                         events[1].transform.position = new Vector3(Screen.width - 200, 174f, 0f); | ||||
|                         events[2].transform.position = new Vector3(Screen.width - 200, 214f, 0f); | ||||
|                         break; | ||||
|                     case 4: | ||||
|                         events[0].transform.position = new Vector3(Screen.width - 200, 134f, 0f); | ||||
|                         events[1].transform.position = new Vector3(Screen.width - 200, 174f, 0f); | ||||
|                         events[2].transform.position = new Vector3(Screen.width - 200, 214f, 0f); | ||||
|                         events[3].transform.position = new Vector3(Screen.width - 200, 254f, 0f); | ||||
|                         break; | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|          | ||||
|         } | ||||
|          | ||||
|     } | ||||
|  | ||||
|     public void CreateEvent(string msg) | ||||
|     { | ||||
|         Instantiate(eventObject, position, Quaternion.identity, parentEventObject); | ||||
|         eventObject.GetComponent<EventScript>().ChangeText(msg); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -1,11 +0,0 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 41974f676d374a946813f4863f75f978 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
| @@ -1,31 +0,0 @@ | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
| using UnityEngine.UI; | ||||
|  | ||||
| public class EventScript : MonoBehaviour | ||||
| { | ||||
|     //[SerializeField] private Text text; | ||||
|     void Start() | ||||
|     { | ||||
|          | ||||
|         Invoke("Delete", 5f); | ||||
|     } | ||||
|  | ||||
|     // Update is called once per frame | ||||
|     void Update() | ||||
|     { | ||||
|          | ||||
|     } | ||||
|  | ||||
|     public void ChangeText(string msg) | ||||
|     { | ||||
|         Text t = GetComponentInChildren<Text>(); | ||||
|         t.text = msg; | ||||
|     } | ||||
|  | ||||
|     void Delete() | ||||
|     { | ||||
|         Destroy(this.gameObject); | ||||
|     } | ||||
| } | ||||
| @@ -1,11 +0,0 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 9be9743e89535f6429f5773fd772d746 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
| @@ -4,7 +4,6 @@ using UnityEngine; | ||||
|  | ||||
| public class LightSwitch : Interactable | ||||
| { | ||||
|     public GameObject GameManager; | ||||
|     public Light m_Light; | ||||
|     public bool isOn; | ||||
|  | ||||
| @@ -30,14 +29,6 @@ public class LightSwitch : Interactable | ||||
|     public override void Interact() | ||||
|     { | ||||
|         isOn = !isOn; | ||||
|  | ||||
|         if (isOn) { | ||||
|             GameManager.GetComponent<EventLog>().CreateEvent("Licht2"); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             GameManager.GetComponent<EventLog>().CreateEvent("Licht1"); | ||||
|         } | ||||
|          | ||||
|         //Debug.Log("Click Light"); | ||||
|         UpdateLight(); | ||||
|   | ||||
| @@ -4,9 +4,8 @@ using UnityEngine; | ||||
|  | ||||
| public class TimeSwitchBtn: Interactable | ||||
| { | ||||
|     public GameObject GameManager; | ||||
|     public bool dark; | ||||
|  | ||||
|     public GameObject GameManager; | ||||
|  | ||||
|     public override string GetDescription() | ||||
|     { | ||||
| @@ -30,12 +29,10 @@ public class TimeSwitchBtn: Interactable | ||||
|  | ||||
|         if (dark) | ||||
|         { | ||||
|             GameManager.GetComponent<EventLog>().CreateEvent("Tag!"); | ||||
|             GameManager.GetComponent<TimeManager>().secondsOfDay = 0; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             GameManager.GetComponent<EventLog>().CreateEvent("Nacht!"); | ||||
|             GameManager.GetComponent<TimeManager>().secondsOfDay = 30000; | ||||
|         } | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 juliuse98
					juliuse98