- Edited
Below is an example on how to move multiple objects along an Architect Curve an also change the objects x and y position in curve space during the movement.
using System.Collections.Generic;
using UnityEngine;
using CurveArchitect.Objects;
public class AnimationExample : MonoBehaviour
{
public ArchitectCurveObject aco;
public int copies;
public float zMaxSpeed;
public float zMinSpeed;
public float xMaxSpeed;
public float xMinSpeed;
public float yMaxSpeed;
public float yMinSpeed;
public float resetRange;
private List<ArchitectCurveObject> acoList = new List<ArchitectCurveObject>();
private List<Vector3> speeds = new List<Vector3>();
Vector3 startPos;
void Start()
{
startPos = aco.localCurvePosition;
ArchitectCurve ac = aco.transform.parent.GetComponent<ArchitectCurve>();
//Create clones and data for clones.
for(int i = 0; i < copies; i++)
{
GameObject clone = Instantiate(aco.gameObject);
ArchitectCurveObject aco2 = clone.GetComponent<ArchitectCurveObject>();
aco2.transform.parent = ac.transform;
float scale = Random.Range(0.2f, 1.2f);
aco2.transform.localScale = new Vector3(scale, scale, scale);
acoList.Add(aco2);
speeds.Add(new Vector3(Random.Range(xMinSpeed, xMaxSpeed), Random.Range(yMinSpeed, yMaxSpeed), Random.Range(zMinSpeed, zMaxSpeed)));
}
}
void Update()
{
//Move all ArchitectCurveObjects
for (int i = 0; i < acoList.Count; i++)
{
Vector3 speed = new Vector3(speeds[i].x * Time.deltaTime, speeds[i].y * Time.deltaTime, speeds[i].z * Time.deltaTime);
acoList[i].localCurvePosition+= speed;
if (resetRange < acoList[i].localCurvePosition.z)
{
acoList[i].localCurvePosition= startPos;
}
}
}
}