Question by
Silverviles · Aug 31, 2021 at 05:03 PM ·
out of memory
I get a Outofmemoryexception. What is wrong with my code ? I'm trying to calculate the positions in which i should spawn the blocks
private void Awake()
{
// Z position of the camera
float screenZ = -Camera.main.transform.position.z;
// Calculate the bounds of the camera
topBounds = -Camera.main.ScreenToWorldPoint(new Vector3(1, 1, screenZ)).y;
bottomBounds = Camera.main.ScreenToWorldPoint(new Vector3(0, 0, screenZ)).y;
leftBounds = Camera.main.ScreenToWorldPoint(new Vector3(0, 0, screenZ)).x;
rightBounds = -Camera.main.ScreenToWorldPoint(new Vector3(1, 1, screenZ)).x;
// support vector2 values for camera points
Vector2 topLeft = new Vector2(leftBounds , topBounds);
Vector2 topRight = new Vector2(rightBounds , topBounds);
Vector2 bottomRight = new Vector2(rightBounds , bottomBounds);
Vector2 bottomLeft = new Vector2(leftBounds , bottomBounds);
// make a list of the camera points and add the values to the list
List<Vector2> pointsList = new List<Vector2>();
pointsList.Add(bottomLeft);
pointsList.Add(topLeft);
pointsList.Add(topRight);
pointsList.Add(bottomRight);
// if theres no colliders then add edgecollider2d and set its points as the list dictates
GameObject colliderSupport = GameObject.FindGameObjectWithTag("ColliderSupport");
if (colliderSupport.GetComponent<EdgeCollider2D>() == null)
{
colliderSupport.AddComponent<EdgeCollider2D>();
EdgeCollider2D collider = colliderSupport.GetComponent<EdgeCollider2D>();
collider.SetPoints(pointsList);
}
CalculateSpawnPositions();
}
private void CalculateSpawnPositions()
{
float firstPositionX = leftBounds + (BlockSpawner.blockWidth / 2) + offsetX;
float lastPositionX = rightBounds - (BlockSpawner.blockWidth / 2) - offsetX;
float firstPositionY = topBounds - BlockSpawner.blockHeight - offsetY;
for (float i = firstPositionX; i < lastPositionX; i = i + BlockSpawner.blockWidth)
{
spawnPositions.Add(new Vector3(i , firstPositionY , 0));
}
}
Comment
Your answer
Follow this Question
Related Questions
fatal error checkdisalowAllocation. Allocating memeort when it is not allowed to allocate memory 4 Answers
failed to create vertex 0 Answers
please help! Could not allocate memory: system out of memory! android build 0 Answers
out of memory 0 Answers
[HDRP][MEMORY LEAK] Unity crashes when reaching maximal possible ram space 0 Answers