Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class MovingBlock : MonoBehaviour {
- public bool direction;
- public Transform[] waypoints;
- private int currentWaypoint = 0;
- public float damping;
- // Use this for initialization
- void Start() {
- }
- // Update is called once per frame
- void Update() {
- transform.position = Vector3.Lerp(transform.position, waypoints[currentWaypoint].position, damping);
- if (transform.position == waypoints[currentWaypoint].position) {
- if ((currentWaypoint < waypoints.Length && direction) || (currentWaypoint > 0 && !direction)) {
- currentWaypoint += direction ? 1 : -1;
- } else {
- direction = !direction;
- }
- }
- }
- /*void OnCollisionEnter(Collision collision) {
- //if (collision.gameObject.layer != 8) {
- // direction = !direction;
- //}
- }
- void OnCollisionStay(Collision collision) {
- if (collision.gameObject.layer != 8) {
- //direction = !direction;
- }
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment