private StageObject SpawnStageObject(StageObject obj, int laneIndex, float xPos, int dir = 0, bool clampPos = true) { obj.Init(dir, laneIndex); float left = leftSide.position.x; float right = rightSide.position.x; Transform lane = lanes[laneIndex]; obj.transform.position = new Vector2(xPos, lane.position.y); if (clampPos) { if (obj.leftEdge < left) { obj.transform.position = new Vector2(left + (obj.centerX - obj.leftEdge), obj.centerY); } else if (obj.rightEdge > right) { obj.transform.position = new Vector2(right - (obj.rightEdge - obj.centerX), obj.centerY); } } return(obj); }