Делаю простенькую 2д игру. Когда запускаю игру(в самом юнити) все нормально, не лагает, но если начинать играть(ну в моем случаи нажимаешь на кубик он прыгает) кубик подпрыгивает, летит и через несколько секунд юнити зависает намертво. Из-за чего это?Оперативная память только на 50% заполнена. Когда код писал все нормально было, но добавил еще несколько строчек и после этого начала юнити зависать
Вот код(может из-за этого?):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CubeJump : MonoBehaviour
{
public GameObject mainCube;
private bool animate, nextBlock = true, lose;
private float scratch_speed = 0.5f, startTime, yPosCube;
void FixedUpdate()
{
if (animate && mainCube.transform.localScale.y > 0.4f)
{
PressCube(-scratch_speed * 3f);
}
else if (!animate && mainCube != null)
{
if (mainCube.transform.localScale.y < 1f)
{
PressCube(scratch_speed * 3f);
}
else if(mainCube.transform.localScale.y != 1f)
{
mainCube.transform.localScale = new Vector3(1f, 1f, 1f);
}
}
if (mainCube != null)
{
if (mainCube.transform.localPosition.y < -8.5f)
{
Destroy(mainCube, 1f);
print("lose");
lose = true;
}
}
}
void OnMouseDown()
{
if(nextBlock && mainCube.GetComponent<Rigidbody>())
{
animate = true;
startTime = Time.time;
}
yPosCube = mainCube.transform.localPosition.y;
}
void OnMouseUp()
{
if (nextBlock && mainCube.GetComponent<Rigidbody>())
{
animate = false;
//Jump
float force, diff;
diff = Time.time - startTime;
if (diff < 3f)
force = 190 * diff;
else
force = 300f;
if (force < 60)
force = 60;
mainCube.GetComponent<Rigidbody>().AddRelativeForce(mainCube.transform.up * force);
mainCube.GetComponent<Rigidbody>().AddRelativeForce(mainCube.transform.right * force);
StartCoroutine(checkCubePos());
nextBlock = false;
}
}
void PressCube (float force)
{
mainCube.transform.localPosition += new Vector3(0f, force * Time.deltaTime, 0f);
mainCube.transform.localScale += new Vector3(0f, force * Time.deltaTime, 0f);
}
IEnumerator checkCubePos ()
{
yield return new WaitForSeconds(1.5f);
if(yPosCube == mainCube.transform.localPosition.y)
{
print("playes lose");
lose = true;
}else {
while (!mainCube.GetComponent<Rigidbody>().IsSleeping())
if (mainCube == null)
break;
yield return new WaitForSeconds(0.05f);
if (!lose)
{
nextBlock = true;
print("Next one");
mainCube.transform.localPosition = new Vector3(-0.3f, mainCube.transform.localPosition.y, mainCube.transform.localPosition.z);
mainCube.transform.eulerAngles = new Vector3(0f, mainCube.transform.eulerAngles.y, 0);
}
}
}
}
Вроде когда что-то в IEnumerator checkCubePos () добавил и начало зависать