mirror of
https://github.com/DerTyp7/traffic-unity.git
synced 2025-10-30 13:17:08 +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();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/BuildingSystem/StreetBuilding.cs.meta
Normal file
11
Assets/Scripts/BuildingSystem/StreetBuilding.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab8ef902838d7534bb1b8062f24d5f82
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user