mirror of
https://github.com/DerTyp7/traffic-unity.git
synced 2025-10-30 13:17:08 +01:00
nodes in street
This commit is contained in:
@@ -6,23 +6,38 @@ public class NodePlacer : MonoBehaviour
|
||||
private GameObject nodeObject;
|
||||
|
||||
[SerializeField]
|
||||
private TrafficNode prevPlacedNode;
|
||||
private TrafficNode selectedPlacedNode;
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
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
|
||||
{
|
||||
selectedPlacedNode = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.B))
|
||||
{
|
||||
Vector3 newPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
newPosition.z = 0;
|
||||
TrafficNode newNode = Instantiate(nodeObject, newPosition, Quaternion.identity).GetComponent<TrafficNode>();
|
||||
|
||||
if (prevPlacedNode != null)
|
||||
if (selectedPlacedNode != null)
|
||||
{
|
||||
prevPlacedNode.AddNextNode(newNode);
|
||||
selectedPlacedNode.AddNextNode(newNode);
|
||||
|
||||
}
|
||||
prevPlacedNode = newNode;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user