You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

36 lines
853 B

using UnityEngine;
public class SplineDecorator : MonoBehaviour {
public BezierSpline spline;
public int frequency;
public bool lookForward;
public Transform[] items;
private void Awake () {
if (frequency <= 0 || items == null || items.Length == 0) {
return;
}
float stepSize = frequency * items.Length;
if (spline.Loop || stepSize == 1) {
stepSize = 1f / stepSize;
}
else {
stepSize = 1f / (stepSize - 1);
}
for (int p = 0, f = 0; f < frequency; f++) {
for (int i = 0; i < items.Length; i++, p++) {
Transform item = Instantiate(items[i]) as Transform;
Vector3 position = spline.GetPoint(p * stepSize);
item.transform.localPosition = position;
if (lookForward) {
item.transform.LookAt(position + spline.GetDirection(p * stepSize));
}
item.transform.parent = transform;
}
}
}
}