Hey guys
I am working on a sports sim of Volleyball where the ball moves to various areas of the court and the movement of the players is driven by where the ball goes, so I have to wait until the ball gets to its destination before starting its next movement. I have gotten as far as the code below
IEnumerator ServeA () {
while (Vector2.Distance(ball.transform.position, serve_left[4]) > 0.01f) {
ball.transform.position = Vector2.MoveTowards (ball.transform.position, serve_left [4], speed);
}
yield return null;
print("Reached the target.");
yield return new WaitForSeconds(3);
print("MyCoroutine is now finished.");
}
void Start () {
StartCoroutine (ServeA ());
}
As a beginner I may be miles off! My while loop is trying to find the distance between the balls current position and destination (Vector2 in an array of coordinates) but right now ball goes immediately to its destination with no movement
Look forward to your feedback!