Beispiel #1
0
    public void Swap()
    {
        var tmpCurrentRoadZone = currentRoadZone;

        currentRoadZone = otherRoadZone;
        otherRoadZone   = tmpCurrentRoadZone;
    }
Beispiel #2
0
    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 : ""));
        }
    }
Beispiel #3
0
    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;
            }
        }
    }
Beispiel #4
0
 public bool IsSameRoad(RoadZone otherRoad)
 {
     return(road.GetInstanceID() == otherRoad.road.GetInstanceID());
 }