Ejemplo n.º 1
0
        private void FindNearestTrack(TrackCart cart)
        {
            Track nearestTrack    = null;
            var   nearestDistance = float.PositiveInfinity;

            foreach (Track track in GameObject.FindObjectsOfType <Track>())
            {
                if (!track.enabled)
                {
                    continue;
                }
                var trackNearest = track.NearestPointAbsolute(cart.transform.position).position;
                var distance     = Vector3.Distance(cart.transform.position, trackNearest);

                if (distance < nearestDistance)
                {
                    nearestTrack    = track;
                    nearestDistance = distance;
                }
            }

            if (!nearestTrack)
            {
                Debug.LogWarning("Could not find a track to put this cart on", cart);
            }

            cart.CurrentTrack = nearestTrack;
        }
        protected IEnumerator WaitForCartToLeave()
        {
            SetTrackSpeed(liftedTrack, liftSpeed);
            Debug.Log("Waiting for cart to leave");

            Action <TrackCart> onLose = cart => {
                if (cart == passengerCart)
                {
                    passengerCart = null;
                }
            };

            //wait for cart to leave
            liftedTrack.onCartLeave += onLose;
            while (passengerCart)
            {
                yield return(null);
            }
            liftedTrack.onCartLeave -= onLose;

            SetTrackSpeed(liftedTrack, 0);

            Debug.Log("Cart is gone");

            stateAction = TravelToBottom;
        }
Ejemplo n.º 3
0
        public void Start()
        {
            cart = GameObject.FindObjectOfType <TrackCart>();

            if (!cart)
            {
                throw new MissingComponentException("A cart must be in the scene for this to work.");
            }
        }
 protected void Start()
 {
     cart = gameObject.GetComponentInParent <TrackCart>();
     rb   = cart.GetComponent <Rigidbody>();
     if (!cart)
     {
         Debug.LogWarning("No parent TrackCart, cannot spin wheels", this);
         return;
     }
 }
Ejemplo n.º 5
0
 /** Watches the current cart. If it leaves, fires events, nulls the cart, and returns false. */
 private bool VerifyCart()
 {
     if (!currentCart || currentCart.CurrentTrack != track)
     {
         var oldCart = currentCart;
         currentCart = null;
         onCartLeft(oldCart);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 6
0
        public void Start()
        {
            //We'll clone AudioSources as we need them, but keep track of the original and the initial volume.
            primarySource                    = GetComponent <AudioSource>();
            primarySource.loop               = true;
            primarySource.playOnAwake        = false;
            primarySource.enabled            = false;
            primarySource.velocityUpdateMode = AudioVelocityUpdateMode.Fixed;

            baseVolume = primarySource.volume;
            cart       = GetComponent <TrackCart>();
            cartRB     = GetComponent <Rigidbody>();
        }
Ejemplo n.º 7
0
        private IEnumerator WaitForCart()
        {
            track.acceleration = new Track.SpeedAndForce();
            track.brakes       = stoppingForce;

            while (!currentCart)
            {
                foreach (var cart in cartsToStop)
                {
                    if (cart.CurrentTrack == track)
                    {
                        currentCart = cart;
                        holdCart    = true;
                        onCartArriving(currentCart);
                        StartCoroutine(StopTheCart());
                        yield break;
                    }
                }

                yield return(fixedWait);
            }
        }
        protected IEnumerator WaitForCart()
        {
            passengerCart = null;
            SetTrackSpeed(liftedTrack, liftSpeed);
            Debug.Log("Waiting for cart");

            Action <TrackCart> onGain = cart => {
                Debug.Log("Cart arrived, waiting for centering");
                passengerCart = cart;
            };

            //wait for a cart
            liftedTrack.onCartEnter += onGain;
            while (!passengerCart)
            {
                yield return(null);
            }
            liftedTrack.onCartEnter -= onGain;

            //wait for it to be closer to the end than the start
            while (
                Vector3.Distance(liftedTrack.TrackAbsoluteStart.position, passengerCart.transform.position)
                <
                Vector3.Distance(liftedTrack.TrackAbsoluteEnd.position, passengerCart.transform.position)
                )
            {
                yield return(null);
            }

            //lock it down
            SetTrackSpeed(liftedTrack, 0);
            SetTrackSpeed(feedInTrack, 0);

            Debug.Log("Cart in place");

            stateAction = TravelToTop;
        }
 internal virtual void FireCartLeave(TrackCart cart)
 {
     onCartLeave(cart);
 }
 internal virtual void FireCartEnter(TrackCart cart)
 {
     onCartEnter(cart);
 }