そして、右に、そして上へと下へのみに。 主なアイデアは一方向に拡大することです。 問題は、新しい空のgameobjectまたはキューブを追加するためにエディタを使用していないことです。 私は、キューブと新しい空のゲームオブジェクトを作成するためにスクリプトを使用しています。どのようにしてキューブを一方向にスケールすることができますか?
シーンウィンドウのエディタにはすでにキューブがあります。スクリプトでは、このキューブを使用して別のキューブを作成/複製し、新しい空のゲームオブジェクトを作成しています。
私はここで答えのように動作するようにしようとした:解決方法2
しかし、この解決策は、エディタを使用していると私は、スクリプトを使用しています。 は、私がこれまで試したどのような:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Test : MonoBehaviour
{
public GameObject gameObjectToRaise;
public float raiseAmount;
public float raiseTotal = 50;
public float speed = 2;
public static bool raised = false;
public int x, z;
private List<GameObject> cubes;
private GameObject go;
public bool randomColor;
public Color[] colorChoices;
Vector3 lp;
Vector3 ls;
// Use this for initialization
void Start()
{
lp = gameObjectToRaise.transform.localPosition;
ls = gameObjectToRaise.transform.localScale;
go = new GameObject();
CreateCubes();
}
void Update()
{
if (DetectPlayer.touched == true)
{
if (raiseAmount < raiseTotal)
{
float raiseThisFrame = speed * Time.deltaTime;
if (raiseAmount + raiseThisFrame > raiseTotal)
{
raiseThisFrame = raiseTotal - raiseAmount;
}
raiseAmount += raiseThisFrame;
gameObjectToRaise.transform.localScale += new Vector3(raiseThisFrame, raiseThisFrame, 0);
go.transform.localScale += new Vector3(raiseThisFrame, raiseThisFrame, 0);
go.transform.position += Vector3.left * (speed/2) * Time.deltaTime;
}
else
{
raised = true;
}
}
}
private List<GameObject> CreateCubes()
{
cubes = new List<GameObject>();
for (int a = 0; a < x; a++)
{
for (int b = 0; b < z; b++)
{
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
if (randomColor)
{
cube.GetComponent<Renderer>().material.color = colorChoices[Random.Range(0, (colorChoices.Length))];
}
cube.transform.position = new Vector3(lp.x - 1, lp.y, lp.z);
cube.transform.Rotate(0, 90, 0);
cubes.Add(cube);
}
}
go.transform.position = new Vector3(lp.x - 2,lp.y,lp.z);
go.transform.Rotate(0, 90, 0);
cubes[0].transform.parent = go.transform;
return cubes;
}
}
しかし、再び、それは両方に行くのVAR(新しい空のゲームオブジェクト)をスケーリングだが、左右両面と私は左にしたいです。
私の最初の質問では既に答えられているとマークされていましたが、リンクの解決策はエディタを使用するときです。スクリプトでやりたいのです。私の最初の質問で