/// <summary> /// Connect wagon to train /// </summary> /// <param name="carCoupler">Current wagon coupler (front or back)</param> /// <param name="otherCarCoupler">Other wagon coupler</param> public void Connect(TrainCarCoupler carCoupler, TrainCarCoupler otherCarCoupler, bool playSFX) { if (coupling == WagonCoupling.Enabled) { if (otherCarCoupler.IsLocomotive) { _locomotive = otherCarCoupler.Locomotive; _reverseAcceleration = (carCoupler.IsBackJoint == otherCarCoupler.IsBackJoint); } else if (otherCarCoupler.IsWagon) { if (!otherCarCoupler.Wagon.IsConected) { return; } _locomotive = otherCarCoupler.Wagon.Locomotive; _reverseAcceleration = (carCoupler.IsBackJoint != otherCarCoupler.IsBackJoint) ? otherCarCoupler.Wagon.ReverseAcceleration : !otherCarCoupler.Wagon.ReverseAcceleration; } TrainPhysics.ConnectTrainCar(_carJoint, otherCarCoupler.GetComponent <Rigidbody>()); _locomotive.wagons.Add(this); _locomotive.UpdateDoorController(); if (playSFX && _sfx.wagonConnectionSFX != null) { _sfx.wagonConnectionSFX.Play(); } } }
private void OnTriggerEnter(Collider other) { TrainController_v3 train = other.GetComponent <TrainController_v3>(); if (train != null) { switch (reverseDirectionMode) { case ReverseDirectionMode.Always: train.acceleration *= -1; break; case ReverseDirectionMode.OnlyIfMovingForward: if (train.acceleration > 0f) { train.acceleration *= -1; } break; case ReverseDirectionMode.OnlyIfMovingBackwards: if (train.acceleration < 0f) { train.acceleration *= -1; } break; } } }
private void OnEnable() { // Parent must be always wagon or locomotive _locomotive = this.transform.parent.GetComponent <TrainController_v3>(); _wagon = this.transform.parent.GetComponent <Wagon_v3>(); _isLocomotive = (_locomotive != null); _isWagon = (_wagon != null); }
private void OnTriggerEnter(Collider other) { TrainController_v3 train = other.GetComponent <TrainController_v3>(); if (train != null) { train.maxSpeedKph = targetSpeedKph; } }
private void OnTriggerEnter(Collider other) { TrainController_v3 train = other.GetComponent <TrainController_v3>(); if (train != null) { train.Honk(); } }
private void OnTriggerEnter(Collider other) { TrainController_v3 train = other.GetComponent <TrainController_v3>(); if (train != null) { if ((triggerType == ZoneTriggerType.Activate && !train.BellOn) || (triggerType == ZoneTriggerType.Deactivate && train.BellOn)) { train.ToogleBell(); } } }
private void OnTriggerEnter(Collider other) { TrainController_v3 train = other.GetComponent <TrainController_v3>(); if (train != null) { if (customEvents != null) { customEvents.Invoke(); } } }
private void OnTriggerEnter(Collider other) { TrainController_v3 train = other.GetComponent <TrainController_v3>(); if (train != null) { if (railroadSwitches == null || railroadSwitches.Count == 0) { Debug.LogWarning("Railroad Switch not set on Switch Trigger"); return; } switch (switchMode) { case SwitchMode.Always: SwitchRails(); break; case SwitchMode.Once: if (!_alreadySwitched) { SwitchRails(); _alreadySwitched = true; } break; case SwitchMode.Random: if (Probability.RandomEvent(randomSwitchProbability)) { SwitchRails(); } break; case SwitchMode.IfActivated: SwitchActivatedRails(); break; case SwitchMode.IfDeactivated: SwitchDeactivatedRails(); break; } } }
/// <summary> /// Disconnect wagon from train /// </summary> public void Disconnect(bool disconnectJoint) { if (disconnectJoint) { _carJoint.connectedBody = jointAnchor; } _locomotive = null; if (_sfx.wagonConnectionSFX != null) { _sfx.wagonConnectionSFX.Play(); } coupling = WagonCoupling.Disabled; if (decouplingSettings == WagonDecouplingSettings.AllowRecoupling) { Invoke("ReenabledCoupling", Mathf.Abs(recouplingTimeout)); } }
// Use this for initialization void Start() { _locomotive = GetComponent <TrainController_v3>(); _doorController = GetComponent <TrainDoorsController>(); }
// Use this for initialization void Start() { _trainController = GetComponent<TrainController_v3>(); UpdateWagonsPassengerTags(); }
private void Start() { _trainController = GetComponent <TrainController_v3>(); UpdateWagonsDoorsControllers(); }
// Use this for initialization void Start() { _trainController = GetComponent <TrainController_v3>(); }