Semi-proper warehouse scrolling using bezier curves

This commit is contained in:
2016-05-23 21:17:41 +02:00
parent 6a84d7c777
commit 116aeab50a
6 changed files with 81 additions and 61 deletions
+35
View File
@@ -0,0 +1,35 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[ExecuteInEditMode]
public class WarehouseColumn : MonoBehaviour {
private BezierCurve curve;
private Transform rows;
private float offset = 0.0f;
void Awake() {
curve = transform.Find("Curve").GetComponent<BezierCurve>();
rows = transform.Find("Rows");
}
void Start () {
}
void Update() {
if (Application.isPlaying) {
offset += Time.deltaTime;
}
foreach (Transform row in rows) {
var i = row.GetSiblingIndex();
var distance = (float)i / (rows.childCount) * curve.length + offset;
distance = Mathf.Repeat(distance, curve.length);
var pos = curve.GetPointAtDistance(distance);
row.position = pos;
}
}
}