Semi-proper warehouse scrolling using bezier curves
This commit is contained in:
Executable
+35
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user