Exemple #1
0
        public void FixedUpdate()
        {
            if (TargetStopIndex != mLastTargetStopIndex)
            {
                mLastTargetStopIndex = TargetStopIndex;
                Audio.Stop();
                Audio.PlayOneShot(OnStopAudio);
                TriggerLoad = Stops [TargetStopIndex].GetComponent <ElevatorTriggerLoad> ();
            }

            EndPosition = Stops [TargetStopIndex].position;
            Moving      = true;

            if (ElevatorPivot.position == EndPosition)
            {
                Moving = false;
                if (Audio.isPlaying)
                {
                    Audio.Stop();
                    Audio.PlayOneShot(OnStopAudio);
                    TriggerLoad = null;
                }
                CurrentStopIndex = TargetStopIndex;
                return;
            }
            else
            {
                if (WaitingForStructure)
                {
                    //Debug.Log ("Elevator is waiting for structure...");
                    return;
                }

                if (!Audio.isPlaying)
                {
                    Audio.Play();
                    Audio.PlayOneShot(OnStartAudio);
                    TravelTime = Mathf.Abs(StartPosition.y - EndPosition.y) * Speed;
                    StartTime  = WorldClock.AdjustedRealTime;
                }
            }

            double  timeSoFar   = WorldClock.AdjustedRealTime - StartTime;
            Vector3 newPosition = Vector3.Lerp(StartPosition, EndPosition, ElevatorMoveCurve.Evaluate((float)(timeSoFar / TravelTime)));

            if (float.IsNaN(newPosition.x))
            {
                newPosition.x = 0f;
            }
            if (float.IsNaN(newPosition.y))
            {
                newPosition.y = 0f;
            }
            if (float.IsNaN(newPosition.z))
            {
                newPosition.z = 0f;
            }
            ElevatorPivot.position = newPosition;
        }
Exemple #2
0
 public void SendToStopIndex(int stop)
 {
     TargetStopIndex = stop;
     StartPosition   = ElevatorPivot.position;
     TriggerLoad     = Stops [TargetStopIndex].GetComponent <ElevatorTriggerLoad> ();
 }