place streets

This commit is contained in:
Janis
2022-12-04 15:09:42 +01:00
parent c94f387a5b
commit 274f5f7cac
18 changed files with 745 additions and 438 deletions

View 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();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ab8ef902838d7534bb1b8062f24d5f82
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: