This commit is contained in:
Janis
2022-12-14 21:47:16 +01:00
parent 274f5f7cac
commit fe2da27074
20 changed files with 407 additions and 197 deletions

View File

@@ -13,12 +13,10 @@ public class NodePlacer : MonoBehaviour
{
if (Input.GetKeyDown(KeyCode.N))
{
Debug.Log("H2213123IT");
RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
if (hit.collider != null)
{
Debug.Log("HIT");
selectedPlacedNode = hit.collider.transform.gameObject.GetComponent<TrafficNode>();
}
else

View File

@@ -3,14 +3,15 @@ using UnityEngine;
public class StreetBuilding : MonoBehaviour
{
GameObject currentStreetPO;
GameObject currentStreetPSO;
Vector3 startPosition;
private void Update()
{
if (Input.GetKeyDown(KeyCode.H))
{
if (currentStreetPO == null)
if (currentStreetPSO == null)
{
StartBuilding();
}
@@ -20,36 +21,41 @@ public class StreetBuilding : MonoBehaviour
}
}
if (currentStreetPO != null && Input.GetKeyDown(KeyCode.J))
if (currentStreetPSO != null)
{
if (currentStreetPO.GetComponent<PlaceableObject>().placeable)
if (Input.GetKeyDown(KeyCode.J))
{
PlaceBuilding();
if (currentStreetPSO.GetComponent<PlaceableStreetObject>().placeable)
{
PlaceBuilding();
}
}
}
}
private void StartBuilding()
{
startPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
startPosition.z = 0;
currentStreetPO = Instantiate(PrefabDictionary.instance.oneWayStreetPO, startPosition, Quaternion.identity);
currentStreetPSO = Instantiate(PrefabDictionary.instance.oneWayStreetPSO, startPosition, Quaternion.identity);
}
private void StopBuilding()
{
Destroy(currentStreetPO);
currentStreetPO = null;
Destroy(currentStreetPSO);
currentStreetPSO = null;
startPosition = Vector3.zero;
}
private void PlaceBuilding()
{
Transform placedTransform = currentStreetPO.transform;
Transform placedTransform = currentStreetPSO.transform;
Instantiate(PrefabDictionary.instance.oneWayStreet, placedTransform.position, placedTransform.rotation).transform.localScale = placedTransform.localScale;
GameObject newStreet = Instantiate(PrefabDictionary.instance.oneWayStreet, placedTransform.position, placedTransform.rotation);
newStreet.transform.localScale = placedTransform.localScale;
newStreet.GetComponent<StreetContainer>().Place();
StopBuilding();
}