2014-11-16 3 views
0

그래서 여기에 내 문제에 대한 더 나은 이해를 제공 할 이미지가 있습니다. 그래서 현재 흰색 블록이 있고 흰색 블록 안에 시안 경계선이 있습니다. 그래서 현재 해결하고 싶은 문제가 있습니다. 흰 상자가 청록색 테두리가있는 상자 밖으로 확장 될 때마다. 시안 색 테두리가있는 상자 안에 있도록 크기를 조정하고 싶습니다. 상단에서 1/5과 같습니다.제한된 영역을 확장했을 때 gameObject의 크기를 조절하십시오.

이 문제를 어떻게 해결할 수 있습니까?

미리 감사드립니다.

enter image description here

편집

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]); 

} 

답변

0

I 유니티의 세부 사항에 익숙하지 않은,하지만 어떤 경우에, 당신은 사각형에서 테스트를 수행해야합니다.

cyan이 청록색 gameObject의 사각형이고 gray이 회색 gameObject의 사각형이라고 가정 해 보겠습니다. 단지 참고 : left 또는 top 속성은 xy 속성 일 수 있으며 rightbottom 속성은 x + widthy + height 일 수 있습니다.

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; 

물론 이것은 양수 -x와 음수 -Y 세계를 가정 한 것입니다. 예 : 아래쪽은 위쪽보다 큰 숫자이고 왼쪽은 오른쪽보다 작은 숫자입니다.

+0

내 코드가 아프다고 생각합니다. – JekasG

관련 문제