Esempio n. 1
0
        /// <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();
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Connect wagons on couplers collision
        /// </summary>
        /// <param name="other"></param>
        private void ConnectOnCollision(Collider other, bool playSFX)
        {
            // Only wagons connect
            if (!_isWagon)
            {
                return;
            }
            // Ignore already connected wagons
            if (_wagon.IsConected)
            {
                return;
            }

            TrainCarCoupler otherCarCoupler = other.GetComponent <TrainCarCoupler>();

            if (otherCarCoupler != null)
            {
                _wagon.Connect(this, otherCarCoupler, playSFX);
            }
        }