diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index a15a27f..224607c 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -235,6 +235,7 @@ power: 1000 totalTravelTime: 0 totalCars: 0 + trafficLights: {fileID: 128843417} --- !u!4 &128843416 Transform: m_ObjectHideFlags: 0 @@ -266,6 +267,7 @@ mode: 0 greenTime: 10 redTime: 2 + lightPhase: 1 --- !u!1 &140411785 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index a15a27f..224607c 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -235,6 +235,7 @@ power: 1000 totalTravelTime: 0 totalCars: 0 + trafficLights: {fileID: 128843417} --- !u!4 &128843416 Transform: m_ObjectHideFlags: 0 @@ -266,6 +267,7 @@ mode: 0 greenTime: 10 redTime: 2 + lightPhase: 1 --- !u!1 &140411785 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Config.cs b/Assets/Scripts/Config.cs index 2ec9709..f764b52 100644 --- a/Assets/Scripts/Config.cs +++ b/Assets/Scripts/Config.cs @@ -14,6 +14,7 @@ public float totalTravelTime = 0f; public int totalCars = 0; public RoadNetwork roadNetwork = new RoadNetwork(); + public TrafficLights trafficLights; public void click(Mode mode, int index) { onClick(); diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index a15a27f..224607c 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -235,6 +235,7 @@ power: 1000 totalTravelTime: 0 totalCars: 0 + trafficLights: {fileID: 128843417} --- !u!4 &128843416 Transform: m_ObjectHideFlags: 0 @@ -266,6 +267,7 @@ mode: 0 greenTime: 10 redTime: 2 + lightPhase: 1 --- !u!1 &140411785 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Config.cs b/Assets/Scripts/Config.cs index 2ec9709..f764b52 100644 --- a/Assets/Scripts/Config.cs +++ b/Assets/Scripts/Config.cs @@ -14,6 +14,7 @@ public float totalTravelTime = 0f; public int totalCars = 0; public RoadNetwork roadNetwork = new RoadNetwork(); + public TrafficLights trafficLights; public void click(Mode mode, int index) { onClick(); diff --git a/Assets/Scripts/Roads/Roads.cs b/Assets/Scripts/Roads/Roads.cs index 983c56a..1c60c10 100644 --- a/Assets/Scripts/Roads/Roads.cs +++ b/Assets/Scripts/Roads/Roads.cs @@ -97,12 +97,18 @@ } drawMode = DrawMode.DragRoad; customNode.lightPhase++; + customNode.isPassable = customNode.lightPhase == 0 || + customNode.lightPhase == config.trafficLights.lightPhase && + config.trafficLights.mode == TrafficLightMode.Green; } else if (Input.GetAxis("Fire2") != 0.0f) { if (drawMode == DrawMode.DragRoad) { return; } - customNode.lightPhase--; drawMode = DrawMode.DragRoad; + customNode.lightPhase--; + customNode.isPassable = customNode.lightPhase == 0 || + customNode.lightPhase == config.trafficLights.lightPhase && + config.trafficLights.mode == TrafficLightMode.Green; } else { drawMode = DrawMode.None; }