SebastianLawe

Untitled

Apr 15th, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class MovingBlock : MonoBehaviour {
  5.     public bool direction;
  6.     public Transform[] waypoints;
  7.     private int currentWaypoint = 0;
  8.     public float damping;
  9.     // Use this for initialization
  10.     void Start() {
  11.  
  12.     }
  13.  
  14.     // Update is called once per frame
  15.     void Update() {
  16.         transform.position = Vector3.Lerp(transform.position, waypoints[currentWaypoint].position, damping);
  17.         if (transform.position == waypoints[currentWaypoint].position) {
  18.             if ((currentWaypoint < waypoints.Length && direction) || (currentWaypoint > 0 && !direction)) {
  19.                 currentWaypoint += direction ? 1 : -1;
  20.             } else {
  21.                 direction = !direction;
  22.             }
  23.         }
  24.     }
  25.  
  26.     /*void OnCollisionEnter(Collision collision) {
  27.         //if (collision.gameObject.layer != 8) {
  28.         //  direction = !direction;
  29.         //}
  30.     }
  31.  
  32.     void OnCollisionStay(Collision collision) {
  33.         if (collision.gameObject.layer != 8) {
  34.             //direction = !direction;
  35.         }
  36.     }*/
  37. }
Advertisement
Add Comment
Please, Sign In to add comment