Can anyone let me know why this while loop seem to be an infinite loop? The starting conditions are
public bool areThrowing = false;
public bool playTouch;
private Collider[] touchList;
The in update var changes are
playTouch = Physics.CheckSphere(ball.transform.position, .5f, LayerMask.GetMask("Selected Player"));
touchList = Physics.OverlapSphere(ball.transform.position, .5f, LayerMask.GetMask("Player"));
And the broken loop is in this method
void changePlayer(GameObject playerObj)
{
areThrowing = true;
SelectedPlayer.rb.velocity = new Vector3(0, 0, 0);
Vector3 target = new Vector3(playerObj.transform.position.x + .3f, playerObj.transform.position.y, playerObj.transform.position.z - 1.2f);
while (areThrowing == true)
{
if (playTouch == true && touchList[0] == ball.GetComponentInParent<Collider>())
{
ball.transform.position = moveMath.parabola(ball.transform.position, target, 3f, animTime / 5f);
}
else if (playTouch == true && touchList[0] != ball.GetComponentInParent<Collider>())
{
ball.transform.position = new Vector3(playerObj.transform.position.x + .3f, playerObj.transform.position.y, playerObj.transform.position.z - 1.2f);
areThrowing = false;
ball.transform.parent = playerObj.transform;
Debug.Log("b");
}
else if (playTouch == false)
{
ball.transform.position = moveMath.parabola(ball.transform.position, target, 3f, animTime / 5f);
}
}
}
}
Let me know if you have any ideas. playTouch is tracking interaction betwen a player gameobject and a ball gameobject. Touch list is tracking that balls interactions.