public void changeRoad(Edge newRoad) { if (road != null && newRoad != null) { var realEnd = direction == 1 ? road.endNode : road.startNode; position -= road.length; road.RemoveCar(this, direction); Debug.Log("RemovCar"); Debug.Log(path.Count); if (realEnd == newRoad.startNode) { direction = 1; } else // realEnd == newRoad.endNode { direction = -1; } } if (newRoad != null) { path.RemoveAt(path.Count - 1); //Debug.Log(path.Count); road = newRoad; road.AddCar(this, direction); //Debug.Log(newRoad.length); } }