Advertisement
EdibleCookie

Mover

Apr 17th, 2018
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Mover : MonoBehaviour {
  6.     // Calling the rail Script\\    
  7.     public Rail rail;
  8.    //^            ^ \\
  9.     private int currentSeg;
  10.     private float transition;
  11.     private bool isCompleted;
  12.  
  13.     private void Update()
  14.     {
  15.  
  16.         if (!rail)
  17.             return;
  18.  
  19.         if (!isCompleted)
  20.             Play();
  21.     }
  22.  
  23.     private void Play()
  24.     {
  25.  
  26.         transition += Time.deltaTime * 1 / 0.45f;
  27.         if(transition > 1)
  28.         {
  29.  
  30.             transition = 0;
  31.             currentSeg++;
  32.         }
  33.         else if(transition < 0)
  34.         {
  35.  
  36.             transition = 1;
  37.             currentSeg--;
  38.         }
  39.  
  40.         transform.position = rail.LinearPosition(currentSeg, transition);
  41.       // TEMPORARY DELETION  transform.rotation = rail.Orientation(currentSeg, transition);
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement