Hello,
I have an hexagonal board, where I can click and draw a path with the mouse to move my character along this path:
![alt text][1]
The Vector3 position of each cell is store in a Vector3 array and my problem is to be able to move smoothly my character along each cell.
For that I try with a coroutine:
void Update() {
if (...) {
StartCoroutine(Move_Routine(this.transform, listPathTransform));
}
}
private IEnumerator Move_Routine(Transform transform, List<Vector3> vectors) {
for(int i = 0; i < vectors.Count - 1; i++) {
float t = 0f;
Vector3 a = vectors*;*
Vector3 b = vectors[i+1];
while (t < 1f) {
t += Time.deltaTime;
transform.position = Vector3.Lerp(a, b, Mathf.SmoothStep(0, 1, t));
yield return null;
}
}
}
I am not very confortable with coroutine yet, and I don’t know if it is a good idea to use it for this problem. The result of my code is that the character will move smoothly from its position to the first selected cell but will not continue (like the for loop never increase i).
Do you have any idea why is it like this or any suggestion about how to solve this problem (coroutine or not)?
Thank you!
[1]: /storage/temp/138822-picture1.png