- Home /
Question by
JekasG · Nov 17, 2014 at 01:20 PM ·
c#gameobjectpositionresize
Resize gameObject when it has extended a restricted area
So here i have an image will provide a better understanding of my problem. So currently i have some white blocks and within the white blocks i have some cyan bordered boxes. So the current problem i want to solve now is. Whenever the white boxes are extended outside the cyan bordered boxes. I want to resize them so they are inside the cyan bordered boxes. Such like the one fifth on from the top.
How can i solve this problem ?
Thanks in advance.
Edit
void Update() {
if( numOfGeneratedGuideline < numOfGuidelineToGenerate ) {
Generate_Guideline_Positons(numOfGeneratedGuideline);
Generate_Platform_Positions_And_Scale(numOfGeneratedGuideline);
Generate_Platforms(numOfGeneratedGuideline);
numOfGeneratedGuideline++;
}
}
void Generate_Guideline_Positons(int i) {
float tempGuidelineOffset = groundHeight + ( guidelineOffset * ( i + 1 ) );
guidelinePosX[i] = worldWidth / 2;
guidelinePosY[i] = tempGuidelineOffset;
guidelinePosZ[i] = 0;
}
void Generate_Platform_Positions_And_Scale(int i) {
randomGuidelineNumber = Random.Range(1, numOfGuidelineToGenerate + 1);
float tempPlatformPosXMin = ( worldWidth - guidelineWidth ) / 2;
Debug.Log(tempPlatformPosXMin);
float tempPlatformPosXMax = worldWidth - tempPlatformPosXMin;
Debug.Log(tempPlatformPosXMax);
float tempPlatformPosY = groundHeight + ( guidelineOffset * ( i + 1 ) );
platformPosX[i] = Random.Range(tempPlatformPosXMin, tempPlatformPosXMax);
platformPosY[i] = tempPlatformPosY;
platformPosZ[i] = 0;
platformScaleX[i] = Random.Range(minPlatformScaleRange, maxPlatformScaleRange);
platformScaleY[i] = 1;
platformScaleZ[i] = 1;
//22 29 36 43 50
}
void Generate_Platforms(int i) {
GameObject newplatform = Instantiate(platformPrefab, new Vector3(platformPosX[i], platformPosY[i], platformPosZ[i]), Quaternion.identity) as GameObject;
newplatform.transform.localScale = new Vector3(platformScaleX[i], platformScaleY[i], platformScaleZ[i]);
}
Comment