0

だからここに私の問題をよりよく理解するための画像があります。現在、私はいくつかの白いブロックを持っており、白いブロック内にはいくつかのシアンの縁取りボックスがあります。だから私が今解決したい現在の問題は. 白いボックスが水色の枠で囲まれたボックスの外側に拡張されるときはいつでも。サイズを変更して、シアンの枠線のボックス内に収まるようにします。上から 5 分の 1 のようなものです。

どうすればこの問題を解決できますか?

前もって感謝します。

ここに画像の説明を入力

編集

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

}
4

1 に答える 1

0

Unity の詳細については詳しくありませんが、いずれにせよ、長方形でテストを行う必要があります。

cyanはシアン ゲーム オブジェクトgrayの Rectangle であり、 はグレー ゲーム オブジェクトの Rectangle であるとしましょう。注意: leftortopプロパティはxandプロパティyである場合があり、rightandbottomプロパティは and である場合がx + widthありy + 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 の世界を想定しています。例: 下は上よりも大きい数値で、左側は右側よりも小さい数値です。

于 2014-11-16T07:50:27.593 に答える