Hello! First, i’m new in C# and Unity so, maybe i don’t see why this is happening when the solution is in front of me…
Ok, when i go to previsualize my project Unity crashes, and this is happening (i suppose) because Unity starts a while. And i can imagine that this isn’t normal. I don’t if the code i write have sense or no, but i suppose the code is normal.
So, the question is here, it’s my pc the problem or it’s the code?
Thanks in advance for anyone can tell me the solution and sorry for my really bad English.
void Update()
{
if(Input.GetKeyDown(KeyCode.W))
{
if (canMoveW == true)
{
Pos = transform.position;
Instantiate(pTail, new Vector3(Pos.x, Pos.y, Pos.z), Quaternion.identity);
while(transform.position.y != Pos.y + 1)
{
transform.Translate(0, moveSpeed, 0);
}
StartCoroutine(WaitForMove(WaitSpeed));
}
}
if (Input.GetKeyDown(KeyCode.S))
{
if (canMoveS == true)
{
Pos = transform.position;
Instantiate(pTail, new Vector3(Pos.x, Pos.y, Pos.z), Quaternion.identity);
while (transform.position.y != Pos.y + 1)
{
transform.Translate(0, -moveSpeed, 0);
}
StartCoroutine(WaitForMove(WaitSpeed));
}
}
if (Input.GetKeyDown(KeyCode.A))
{
if (canMoveA == true)
{
Pos = transform.position;
Instantiate(pTail, new Vector3(Pos.x, Pos.y, Pos.z), Quaternion.identity);
while (transform.position.y != Pos.y + 1)
{
transform.Translate(-moveSpeed, 0, 0);
}
StartCoroutine(WaitForMove(WaitSpeed));
}
}
if (Input.GetKeyDown(KeyCode.D))
{
if (canMoveD == true)
{
Pos = transform.position;
Instantiate(pTail, new Vector3(Pos.x, Pos.y, Pos.z), Quaternion.identity);
while (transform.position.y != Pos.y + 1)
{
transform.Translate(moveSpeed, 0, 0);
}
StartCoroutine(WaitForMove(WaitSpeed));
}
}
}