mirror of
				https://github.com/DerTyp7/fps-citybuild-unity.git
				synced 2025-10-31 13:17:07 +01:00 
			
		
		
		
	started working on Building rework
This commit is contained in:
		
							
								
								
									
										35
									
								
								Assets/Buildings/Scripts/BuildingPlacement.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Assets/Buildings/Scripts/BuildingPlacement.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
|  | ||||
| public class BuildingPlacement : MonoBehaviour | ||||
| { | ||||
|     [SerializeField] private GameObject terrain; | ||||
|     [SerializeField] private GameObject prefab; | ||||
|  | ||||
|     Ray ray; | ||||
|     private Canvas hud; | ||||
|  | ||||
|     private void Start() | ||||
|     { | ||||
|         hud = GameObject.Find("HUD").GetComponent<Canvas>(); | ||||
|     } | ||||
|  | ||||
|     void Update() | ||||
|     { | ||||
|         // Build Button Handler | ||||
|         if (Input.GetButtonDown("Build")) | ||||
|         { // Wenn man den Button 'B' | ||||
|              //Get HUD Canvas | ||||
|             hud.enabled = false; //Hide HUD | ||||
|  | ||||
|             ray = Camera.main.ScreenPointToRay(Input.mousePosition); | ||||
|             RaycastHit hitData; | ||||
|             if (terrain.GetComponent<Collider>().Raycast(ray, out hitData, Mathf.Infinity)) | ||||
|             { | ||||
|                 Instantiate(prefab, hitData.point, Quaternion.identity); | ||||
|  | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 DerTyp187
					DerTyp187