// Start is called before the first frame update void Start() { var camBounds = DisplayUtil.GetCameraBounds(); while (boxSprite.transform.position.x - boxSprite.bounds.size.x / 2 < camBounds.xMin) { box.transform.position += Vector3.right * 0.1f; } while (boxSprite.transform.position.x + boxSprite.bounds.size.x / 2 > camBounds.xMax) { box.transform.position += Vector3.left * 0.1f; } }
private void OnDrawGizmos() { startX = transform.position.x; startY = transform.position.y; var camBounds = DisplayUtil.GetCameraBounds(); var realGridWidth = widthInUnits * camBounds.width; var realGridHeight = heightInUnits * camBounds.height; Gizmos.color = gridColor; for (int i = 0; i < widthInUnits + 1; i++) { Gizmos.DrawLine(new Vector3(i * camBounds.width + startX, startY, 0), new Vector3(i * camBounds.width + startX, realGridHeight + startY, 0)); } for (int j = 0; j < heightInUnits + 1; j++) { Gizmos.DrawLine(new Vector3(startX, j * camBounds.height + startY, 0), new Vector3(realGridWidth + startX, j * camBounds.height + startY, 0)); } }
// Use this for initialization private void Start() { bounds = DisplayUtil.GetCameraBounds(); currentPos = transform.position; }