public void Swap() { var tmpCurrentRoadZone = currentRoadZone; currentRoadZone = otherRoadZone; otherRoadZone = tmpCurrentRoadZone; }
private void OnCollisionEnter2D(Collision2D collision) { var tmpRoadZone = collision.gameObject.GetComponent <RoadZone>(); if (tmpRoadZone != null) { //print("roadZone name = " + tmpRoadZone.gameObject.name); // set object to current road if no road is set if (currentRoadZone == null) { currentRoadZone = tmpRoadZone; } if (tmpRoadZone.IsSameRoad(currentRoadZone)) { currentRoadZone = tmpRoadZone; } else { otherRoadZone = tmpRoadZone; } //print(currentRoadZone + " " + otherRoadZone); //print("current: " + currentRoadZone.gameObject.name + ", other: " + (otherRoadZone != null ? otherRoadZone.gameObject.name : "")); } }
private void OnCollisionExit2D(Collision2D collision) { var roadzone = collision.gameObject.GetComponent <RoadZone>(); if (roadzone) { var name = roadzone.road.gameObject.name; //print("exit " + name); if (otherRoadZone != null && name == otherRoadZone.road.gameObject.name) { otherRoadZone = null; } if (currentRoadZone != null && name == currentRoadZone.road.gameObject.name) { currentRoadZone = null; } } }
public bool IsSameRoad(RoadZone otherRoad) { return(road.GetInstanceID() == otherRoad.road.GetInstanceID()); }