mirror of
				https://github.com/DerTyp7/traffic-unity.git
				synced 2025-10-30 21:27:07 +01:00 
			
		
		
		
	place streets
This commit is contained in:
		
							
								
								
									
										56
									
								
								Assets/Scripts/BuildingSystem/StreetBuilding.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								Assets/Scripts/BuildingSystem/StreetBuilding.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,56 @@ | ||||
| using UnityEngine; | ||||
|  | ||||
| public class StreetBuilding : MonoBehaviour | ||||
| { | ||||
|  | ||||
|     GameObject currentStreetPO; | ||||
|     Vector3 startPosition; | ||||
|  | ||||
|     private void Update() | ||||
|     { | ||||
|         if (Input.GetKeyDown(KeyCode.H)) | ||||
|         { | ||||
|             if (currentStreetPO == null) | ||||
|             { | ||||
|                 StartBuilding(); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 StopBuilding(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         if (currentStreetPO != null && Input.GetKeyDown(KeyCode.J)) | ||||
|         { | ||||
|             if (currentStreetPO.GetComponent<PlaceableObject>().placeable) | ||||
|             { | ||||
|                 PlaceBuilding(); | ||||
|             } | ||||
|  | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void StartBuilding() | ||||
|     { | ||||
|         startPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); | ||||
|         startPosition.z = 0; | ||||
|  | ||||
|         currentStreetPO = Instantiate(PrefabDictionary.instance.oneWayStreetPO, startPosition, Quaternion.identity); | ||||
|     } | ||||
|  | ||||
|     private void StopBuilding() | ||||
|     { | ||||
|         Destroy(currentStreetPO); | ||||
|         currentStreetPO = null; | ||||
|         startPosition = Vector3.zero; | ||||
|     } | ||||
|  | ||||
|     private void PlaceBuilding() | ||||
|     { | ||||
|         Transform placedTransform = currentStreetPO.transform; | ||||
|  | ||||
|         Instantiate(PrefabDictionary.instance.oneWayStreet, placedTransform.position, placedTransform.rotation).transform.localScale = placedTransform.localScale; | ||||
|  | ||||
|         StopBuilding(); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Janis
					Janis