Beispiel #1
0
 // mb add a second collision box for the front and back part to pref multimple checks
 void OnTriggerStay2D(Collider2D other)
 {
     if (other.gameObject.transform.position.x < transform.position.x && other.gameObject.name.Contains("Pedestrian") /*&& transform.position.y == other.gameObject.transform.position.y*/)
     {
         behindPedestrian = other.gameObject.GetComponent <Pedestrian>();
         behindPedestrian.StopEngine();
         //Debug.Log ("Engine stop");
     }
     if (CurrentAngle >= 135 && CurrentAngle < 225)
     {
         if (other.gameObject.transform.position.x > transform.position.x && other.gameObject.name.Contains("Pedestrian") /*&& transform.position.y == other.gameObject.transform.position.y*/)
         {
             behindPedestrian = other.gameObject.GetComponent <Pedestrian>();
             behindPedestrian.StopEngine();
             //Debug.Log ("Engine stop");
         }
     }
     if (CurrentAngle >= 225 && CurrentAngle < 315)
     {
         if (other.gameObject.transform.position.y > transform.position.y && other.gameObject.name.Contains("Pedestrian") /*&& transform.position.x == other.gameObject.transform.position.x*/)
         {
             behindPedestrian = other.gameObject.GetComponent <Pedestrian>();
             behindPedestrian.StopEngine();
             //Debug.Log ("Engine stop");
         }
     }
     if (CurrentAngle >= 45 && CurrentAngle < 135)
     {
         if (other.gameObject.transform.position.y < transform.position.y && other.gameObject.name.Contains("Pedestrian") /*&& transform.position.x == other.gameObject.transform.position.x*/)
         {
             behindPedestrian = other.gameObject.GetComponent <Pedestrian>();
             behindPedestrian.StopEngine();
             //Debug.Log ("Engine stop");
         }
     }
     //Debug.Log ("Collison");
     //Debug.Log (other.gameObject.name);
 }
    void OnTriggerStay2D(Collider2D other)
    {
        try
        {
            if (Car == null && Car != other)
            {
                Car  = other.gameObject.GetComponent <Car>();
                Car2 = other.gameObject.GetComponent <Car>();
                Car3 = other.gameObject.GetComponent <Car>();
                Car4 = other.gameObject.GetComponent <Car>();
            }
            if (Car == Car2 && other != Car)
            {
                Car2 = other.gameObject.GetComponent <Car>();
            }
            if (Car == Car3 || Car == Car2 && other != Car || other != Car2)
            {
                Car3 = other.gameObject.GetComponent <Car>();
            }
            if (Car == Car4 || Car == Car3 || Car == Car2 && other != Car || other != Car2 || other != Car3)
            {
                Car4 = other.gameObject.GetComponent <Car>();
            }
        }
        catch
        {
        }
        try { PedestrianTemp = other.gameObject.GetComponent <Pedestrian>(); }
        catch
        {
        }
        try { BikeTemp = other.gameObject.GetComponent <Bike>(); }
        catch
        {
        }
        try { BoatTemp = other.gameObject.GetComponent <Boat>(); }
        catch {}

        if (PedestrianTemp != null)
        {
            Pedestrian = PedestrianTemp;
        }
        if (Pedestrian != null && PedestrianTemp != Pedestrian)
        {
            Pedestrian2 = PedestrianTemp;
        }
        if (BikeTemp != null)
        {
            Bike = BikeTemp;
        }
        if (Bike != null && BikeTemp != Bike)
        {
            Bike2 = BikeTemp;
        }
        if (BoatTemp != null)
        {
            Boat = BoatTemp;
        }


        if (greenLight && Car != null)
        {
            try
            {
                Car.StartEngine();
            }
            catch
            {
            }
            try
            {
                Car2.StartEngine();
            }
            catch
            {
            }
            try
            {
                Car3.StartEngine();
            }
            catch
            {
            }
            try
            {
                Car4.StartEngine();
            }
            catch
            {
            }
        }
        else if (Car != null)
        {
            try
            {
                Car.StopEngine();
            }
            catch
            {
            }
            try
            {
                Car2.StopEngine();
            }
            catch
            {
            }
            try
            {
                Car3.StopEngine();
            }
            catch
            {
            }
            try
            {
                Car4.StopEngine();
            }
            catch
            {
            }
        }

        if (greenLight && Pedestrian != null)
        {
            try
            {
                Pedestrian.StartEngine();
            }
            catch
            {
            }
            try
            {
                Pedestrian2.StartEngine();
            }
            catch
            {
            }
        }
        else if (Pedestrian != null)
        {
            try
            {
                Pedestrian.StopEngine();
            }
            catch
            {
            }
            try
            {
                Pedestrian2.StopEngine();
            }
            catch
            {
            }
        }
        if (greenLight && Bike != null)
        {
            try
            {
                Bike.StartEngine();
            }
            catch
            {
            }
            try
            {
                Bike2.StartEngine();
            }
            catch
            {
            }
        }
        else if (Bike != null)
        {
            try
            {
                Bike.StopEngine();
            }
            catch
            {
            }
            try
            {
                Bike2.StopEngine();
            }
            catch
            {
            }
        }

        if (greenLight && Boat != null)
        {
            Boat.StartEngine();
        }
        else if (Boat != null)
        {
            Boat.StopEngine();
        }
    }