// Update is called once per frame void Update() { try { if (greenLight && Bike != null) { Bike.StartEngine(); Bike = null; } } catch { } try { if (greenLight && Car != null) { Car.StartEngine(); Car2.StartEngine(); Car2 = null; Car = null; } } catch { } try { if (greenLight && Pedestrian != null) { Pedestrian.StartEngine(); Pedestrian = null; } } catch { } try { if (greenLight && Boat != null) { Boat.StartEngine(); Boat = null; } } catch { } }
void OnTriggerExit2D(Collider2D other) { if (other.gameObject.transform.position.x < transform.position.x && other.gameObject.name.Contains("Pedestrian")) { //Car behindCar = other.gameObject.GetComponent<Pedestrian> (); behindPedestrian.StartEngine(); //Debug.Log ("Engine start"); } }
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(); } }