C# 当游戏对象扩展了限制区域时,调整其大小
因此,这里我有一个图像将提供一个更好的理解我的问题。 现在我有一些白色方块,在白色方块中我有一些青色边框的方块。 所以我现在要解决的问题是。 每当白色框延伸到青色边框框外时。我想调整它们的大小,使它们位于青色边框框内。 比如从顶部开始的五分之一 我怎样才能解决这个问题 提前谢谢 编辑C# 当游戏对象扩展了限制区域时,调整其大小,c#,unity3d,resize,block,gameobject,C#,Unity3d,Resize,Block,Gameobject,因此,这里我有一个图像将提供一个更好的理解我的问题。 现在我有一些白色方块,在白色方块中我有一些青色边框的方块。 所以我现在要解决的问题是。 每当白色框延伸到青色边框框外时。我想调整它们的大小,使它们位于青色边框框内。 比如从顶部开始的五分之一 我怎样才能解决这个问题 提前谢谢 编辑 我不熟悉Unity的细节,但是在任何情况下,您都需要在矩形上进行测试 假设青色是青色游戏对象的矩形,灰色是灰色游戏对象的矩形。请注意:左侧或顶部属性可能是x和y属性,而右侧和底部属性可能是x+宽度和y+高度 当然,
我不熟悉Unity的细节,但是在任何情况下,您都需要在矩形上进行测试 假设青色是青色游戏对象的矩形,灰色是灰色游戏对象的矩形。请注意:左侧或顶部属性可能是x和y属性,而右侧和底部属性可能是x+宽度和y+高度 当然,这是假设一个正x和负y的世界。例如,底部的数字大于顶部,左侧的数字小于右侧
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]);
}
if (gray.left < cyan.left) //Out of bounds on the left
gray.left = cyan.left;
if (gray.right > cyan.right) //Out of bounds on the right / past the right edge
gray.right = cyan.right;
if (gray.top < cyan.top) //Out of bounds on the top
gray.top = cyan.top;
if (gray.bottom > cyan.bottom) //Out of bounds on the bottom / gray stretches below cyan
gray.bottom = cyan.bottom;