I'm attempting to create a framework wherein I can move an object, regardless of type, along a set path defined by an n-dimensional array of path waypoints.
In the following method, `_currentTarget` will always be the next waypoint (index) in the array, or the previous point if we've reached `points.Length` (this is obviously not currently implemented, I just mention it for context).
As written, this method returns the error: `Operator '<' cannot be applied to operands of type 'Transform' and 'int'`
void MoveObject(Transform[] points)
{
MovableObject.transform.position = Vector3.MoveTowards(MovableObject.transform.position, _currentTarget, MoveSpeed*Time.deltaTime);
var i = 0;
do
{
// Move the object
} while (points[i] < points.Length);
}
I've found out that `Array.Length` returns not the number of indices, as I had thought, but the total number of elements in the array. So, for a Transform component, we're talking nine elements per index, right? While I think I understand why it doesn't work, I still can't figure out how to fix it.
How would you refactor the method, given the above constraints?
↧