diff --git a/Assets/Scripts/Car/Car.cs b/Assets/Scripts/Car/Car.cs index 63de2a1..32d7522 100644 --- a/Assets/Scripts/Car/Car.cs +++ b/Assets/Scripts/Car/Car.cs @@ -142,7 +142,11 @@ if (needsBraking(totalDistance, getMaxSpeed(currentRoad, currentRoadPosition))) { return true; } - if (currentRoad.nodes[0] is CustomNode && !((CustomNode)currentRoad.nodes[0]).isPassable && needsBraking(totalDistance - 2f, 0f)) { + if (currentRoad != road && + currentRoad.nodes[0] is CustomNode && + !((CustomNode)currentRoad.nodes[0]).isPassable && + needsBraking(totalDistance - 2f, 0f)) { + return true; } } diff --git a/Assets/Scripts/Car/Car.cs b/Assets/Scripts/Car/Car.cs index 63de2a1..32d7522 100644 --- a/Assets/Scripts/Car/Car.cs +++ b/Assets/Scripts/Car/Car.cs @@ -142,7 +142,11 @@ if (needsBraking(totalDistance, getMaxSpeed(currentRoad, currentRoadPosition))) { return true; } - if (currentRoad.nodes[0] is CustomNode && !((CustomNode)currentRoad.nodes[0]).isPassable && needsBraking(totalDistance - 2f, 0f)) { + if (currentRoad != road && + currentRoad.nodes[0] is CustomNode && + !((CustomNode)currentRoad.nodes[0]).isPassable && + needsBraking(totalDistance - 2f, 0f)) { + return true; } } diff --git a/Assets/Scripts/Roads/Node/Node.cs b/Assets/Scripts/Roads/Node/Node.cs index aa211d1..10fe8b2 100644 --- a/Assets/Scripts/Roads/Node/Node.cs +++ b/Assets/Scripts/Roads/Node/Node.cs @@ -3,12 +3,12 @@ using UnityEngine; public abstract class Node { - private FlatCircleRenderer circle = new FlatCircleRenderer(0.2f, 0.05f, 32); + private FlatCircleRenderer circle = new FlatCircleRenderer(0.2f, 0.1f, 32); private FlatCircleRenderer fullCircle = new FlatCircleRenderer(0f, 1f, 32); public Vector3 position; public List roads = new List(); - public GameObject gameObject; + public GameObject gameObject, circleObject, roadObject; public Vector3 direction; public Config config; private Transform parent; @@ -30,17 +30,17 @@ nodeData.node = this; nodeData.config = config; - GameObject nodeCircle = new GameObject(); - nodeCircle.AddComponent().material = config.roadEditMaterial; - nodeCircle.AddComponent().mesh = circle.mesh; - nodeCircle.transform.parent = gameObject.transform; - nodeCircle.transform.localPosition = new Vector3(0f, 0.01f, 0f); + circleObject = new GameObject(); + circleObject.AddComponent().material = config.roadEditMaterial; + circleObject.AddComponent().mesh = circle.mesh; + circleObject.transform.parent = gameObject.transform; + circleObject.transform.localPosition = new Vector3(0f, 0.01f, 0f); - GameObject nodeRoad = new GameObject(); - nodeRoad.AddComponent().material = config.roadMaterial; - nodeRoad.AddComponent().mesh = fullCircle.mesh; - nodeRoad.transform.parent = gameObject.transform; - nodeRoad.transform.localPosition = Vector3.zero; + roadObject = new GameObject(); + roadObject.AddComponent().material = config.roadMaterial; + roadObject.AddComponent().mesh = fullCircle.mesh; + roadObject.transform.parent = gameObject.transform; + roadObject.transform.localPosition = Vector3.zero; update(); return this; } diff --git a/Assets/Scripts/Car/Car.cs b/Assets/Scripts/Car/Car.cs index 63de2a1..32d7522 100644 --- a/Assets/Scripts/Car/Car.cs +++ b/Assets/Scripts/Car/Car.cs @@ -142,7 +142,11 @@ if (needsBraking(totalDistance, getMaxSpeed(currentRoad, currentRoadPosition))) { return true; } - if (currentRoad.nodes[0] is CustomNode && !((CustomNode)currentRoad.nodes[0]).isPassable && needsBraking(totalDistance - 2f, 0f)) { + if (currentRoad != road && + currentRoad.nodes[0] is CustomNode && + !((CustomNode)currentRoad.nodes[0]).isPassable && + needsBraking(totalDistance - 2f, 0f)) { + return true; } } diff --git a/Assets/Scripts/Roads/Node/Node.cs b/Assets/Scripts/Roads/Node/Node.cs index aa211d1..10fe8b2 100644 --- a/Assets/Scripts/Roads/Node/Node.cs +++ b/Assets/Scripts/Roads/Node/Node.cs @@ -3,12 +3,12 @@ using UnityEngine; public abstract class Node { - private FlatCircleRenderer circle = new FlatCircleRenderer(0.2f, 0.05f, 32); + private FlatCircleRenderer circle = new FlatCircleRenderer(0.2f, 0.1f, 32); private FlatCircleRenderer fullCircle = new FlatCircleRenderer(0f, 1f, 32); public Vector3 position; public List roads = new List(); - public GameObject gameObject; + public GameObject gameObject, circleObject, roadObject; public Vector3 direction; public Config config; private Transform parent; @@ -30,17 +30,17 @@ nodeData.node = this; nodeData.config = config; - GameObject nodeCircle = new GameObject(); - nodeCircle.AddComponent().material = config.roadEditMaterial; - nodeCircle.AddComponent().mesh = circle.mesh; - nodeCircle.transform.parent = gameObject.transform; - nodeCircle.transform.localPosition = new Vector3(0f, 0.01f, 0f); + circleObject = new GameObject(); + circleObject.AddComponent().material = config.roadEditMaterial; + circleObject.AddComponent().mesh = circle.mesh; + circleObject.transform.parent = gameObject.transform; + circleObject.transform.localPosition = new Vector3(0f, 0.01f, 0f); - GameObject nodeRoad = new GameObject(); - nodeRoad.AddComponent().material = config.roadMaterial; - nodeRoad.AddComponent().mesh = fullCircle.mesh; - nodeRoad.transform.parent = gameObject.transform; - nodeRoad.transform.localPosition = Vector3.zero; + roadObject = new GameObject(); + roadObject.AddComponent().material = config.roadMaterial; + roadObject.AddComponent().mesh = fullCircle.mesh; + roadObject.transform.parent = gameObject.transform; + roadObject.transform.localPosition = Vector3.zero; update(); return this; } diff --git a/Assets/Scripts/Roads/Node/NodeData.cs b/Assets/Scripts/Roads/Node/NodeData.cs index 24b2c47..d923cbc 100644 --- a/Assets/Scripts/Roads/Node/NodeData.cs +++ b/Assets/Scripts/Roads/Node/NodeData.cs @@ -13,4 +13,19 @@ void OnDestroy() { node.config.roadNetwork.nodes.Remove(node); } + + private void Update() { + if (!(node is CustomNode)) { + return; + } + CustomNode customNode = (CustomNode) node; + if (customNode.lightPhase == 0) { + return; + } + if (customNode.isPassable) { + node.circleObject.GetComponent().material = config.carAccelerationMaterial; + } else { + node.circleObject.GetComponent().material = config.carBrakingMaterial; + } + } } diff --git a/Assets/Scripts/Car/Car.cs b/Assets/Scripts/Car/Car.cs index 63de2a1..32d7522 100644 --- a/Assets/Scripts/Car/Car.cs +++ b/Assets/Scripts/Car/Car.cs @@ -142,7 +142,11 @@ if (needsBraking(totalDistance, getMaxSpeed(currentRoad, currentRoadPosition))) { return true; } - if (currentRoad.nodes[0] is CustomNode && !((CustomNode)currentRoad.nodes[0]).isPassable && needsBraking(totalDistance - 2f, 0f)) { + if (currentRoad != road && + currentRoad.nodes[0] is CustomNode && + !((CustomNode)currentRoad.nodes[0]).isPassable && + needsBraking(totalDistance - 2f, 0f)) { + return true; } } diff --git a/Assets/Scripts/Roads/Node/Node.cs b/Assets/Scripts/Roads/Node/Node.cs index aa211d1..10fe8b2 100644 --- a/Assets/Scripts/Roads/Node/Node.cs +++ b/Assets/Scripts/Roads/Node/Node.cs @@ -3,12 +3,12 @@ using UnityEngine; public abstract class Node { - private FlatCircleRenderer circle = new FlatCircleRenderer(0.2f, 0.05f, 32); + private FlatCircleRenderer circle = new FlatCircleRenderer(0.2f, 0.1f, 32); private FlatCircleRenderer fullCircle = new FlatCircleRenderer(0f, 1f, 32); public Vector3 position; public List roads = new List(); - public GameObject gameObject; + public GameObject gameObject, circleObject, roadObject; public Vector3 direction; public Config config; private Transform parent; @@ -30,17 +30,17 @@ nodeData.node = this; nodeData.config = config; - GameObject nodeCircle = new GameObject(); - nodeCircle.AddComponent().material = config.roadEditMaterial; - nodeCircle.AddComponent().mesh = circle.mesh; - nodeCircle.transform.parent = gameObject.transform; - nodeCircle.transform.localPosition = new Vector3(0f, 0.01f, 0f); + circleObject = new GameObject(); + circleObject.AddComponent().material = config.roadEditMaterial; + circleObject.AddComponent().mesh = circle.mesh; + circleObject.transform.parent = gameObject.transform; + circleObject.transform.localPosition = new Vector3(0f, 0.01f, 0f); - GameObject nodeRoad = new GameObject(); - nodeRoad.AddComponent().material = config.roadMaterial; - nodeRoad.AddComponent().mesh = fullCircle.mesh; - nodeRoad.transform.parent = gameObject.transform; - nodeRoad.transform.localPosition = Vector3.zero; + roadObject = new GameObject(); + roadObject.AddComponent().material = config.roadMaterial; + roadObject.AddComponent().mesh = fullCircle.mesh; + roadObject.transform.parent = gameObject.transform; + roadObject.transform.localPosition = Vector3.zero; update(); return this; } diff --git a/Assets/Scripts/Roads/Node/NodeData.cs b/Assets/Scripts/Roads/Node/NodeData.cs index 24b2c47..d923cbc 100644 --- a/Assets/Scripts/Roads/Node/NodeData.cs +++ b/Assets/Scripts/Roads/Node/NodeData.cs @@ -13,4 +13,19 @@ void OnDestroy() { node.config.roadNetwork.nodes.Remove(node); } + + private void Update() { + if (!(node is CustomNode)) { + return; + } + CustomNode customNode = (CustomNode) node; + if (customNode.lightPhase == 0) { + return; + } + if (customNode.isPassable) { + node.circleObject.GetComponent().material = config.carAccelerationMaterial; + } else { + node.circleObject.GetComponent().material = config.carBrakingMaterial; + } + } } diff --git a/Assets/Scripts/Roads/Roads.cs b/Assets/Scripts/Roads/Roads.cs index 7c0a7c9..ded4420 100644 --- a/Assets/Scripts/Roads/Roads.cs +++ b/Assets/Scripts/Roads/Roads.cs @@ -96,11 +96,13 @@ return; } drawMode = DrawMode.DragRoad; - Debug.Log(customNode.isPassable = !customNode.isPassable); + customNode.lightPhase++; // todo: increment or decrement + customNode.isPassable = !customNode.isPassable; } else if (Input.GetAxis("Fire2") != 0.0f) { if (drawMode == DrawMode.DragRoad) { return; } + customNode.lightPhase--; drawMode = DrawMode.DragRoad; } else { drawMode = DrawMode.None;