Beispiel #1
0
    /// <summary>
    /// Main function for moving this object
    /// </summary>
    private void Play(bool forward = true)
    {
        // Calculate the true speed using the magnitude
        float mag = (rail.nodes[currentSeg + 1].position - rail.nodes[currentSeg].position).magnitude;
        float s   = (Time.deltaTime * 1 / mag) * speed;

        transition += (forward) ? s : -s;

        // If at the end
        if (transition > 1)
        {
            PlayForward();
        }
        // Else if at the start
        else if (transition < 0)
        {
            PlayBackwards();
        }

        transform.position = rail.Position(currentSeg, transition, play, isCompleted);
        transform.rotation = rail.Rotation(currentSeg, transition);
    }