Код: Выделить всё
void RotateCubes(Vector3 newRotationAngles)
{
foreach (GameObject cube in cubes)
{
cube.transform.localRotation = Quaternion.Euler(newRotationAngles);
}
}
Код: Выделить всё
void Start()
{
float xPos = 0;
float zPos = correctPosition.z;
RotateCubes(individualCubeRotate);
for (int i = 0; i < numberOfCubes; i++)
{
float height = Random.Range(minHeight, maxHeight);
float spacing = Random.Range(minSpacing, maxSpacing);
Vector3 position = new Vector3(xPos, height / 2f, zPos);
GameObject newCube = Instantiate(cubePrefab, position, Quaternion.identity, parentTransform);
// Reset transformations first
newCube.transform.localPosition = Vector3.zero;
newCube.transform.localScale = Vector3.one;
newCube.transform.localRotation = Quaternion.identity;
newCube.transform.localPosition = position; // Use position
newCube.transform.localScale = new Vector3(1, height, 1);
newCube.transform.localRotation = Quaternion.Euler(rotationAngles); // Ensure local rotation
if (newCube == null)
{
Debug.LogWarning("!NewCube is null!");
}
else if (parentTransform == null)
{
Debug.LogWarning("!ParentTransform is null!");
}
// Apply individual rotation to each cube
newCube.transform.rotation = Quaternion.Euler(rotationAngles);
cubes.Add(newCube);
xPos += spacing;
}
// Apply uniform rotation to the parent
parentTransform.rotation = Quaternion.Euler(rotationAngles);
// Set the parent object to the correct position
parentTransform.position = correctPosition + parentOffset;
// Set the parent object's scale
parentTransform.localScale = scale;
// Debug log to show the final scale
Debug.Log("Final Scale: " + parentTransform.localScale);
}
Код: Выделить всё
public individualCubeRotate = new Vector3(0f, 0f, -90f);Assets\SpawnCubes.cs(18,33): ошибка CS1519: неверный токен '=' в классе Объявление члена , записи, структуры или интерфейса
Assets\SpawnCubes.cs(18,47): ошибка CS1001: ожидается идентификатор
Assets\SpawnCubes .cs(18,49): ошибка CS1031: ожидается тип
Assets\SpawnCubes.cs(18,49): ошибка CS1001: ожидается идентификатор
Assets\SpawnCubes.cs(18,51): ошибка CS1031: ожидается тип
Assets\SpawnCubes.cs(18,51): ошибка CS1001: ожидается идентификатор
Assets\SpawnCubes.cs(18,51): ошибка CS1001: ожидается идентификатор
Assets\SpawnCubes.cs(18,55): ошибка CS1031: ожидается тип p>
Assets\SpawnCubes.cs(18,55): ошибка CS1001: ожидается идентификатор
Assets\SpawnCubes.cs(18,55): ошибка CS1003: Ожидается синтаксическая ошибка, ','
Я попробовал с самой простой ошибкой - синтаксической ошибкой, в которой отсутствовал символ ",". Итак, я проверил запятые и, конечно же, не нашел ошибок. По мнению моего мозга и глаз. Итак, теперь я перешел к тем, которые выглядят довольно сложно. Первым был CS1001. Я посмотрел его в Интернете, и он по-прежнему выглядел правильно. Я перешел к ошибке типа и поискал CS1031. И я нашел это и не понял, почему оно там. Я ожидал, что кубики будут вращаться по отдельности. Другая переменная вращения относилась к целому.
Подробнее здесь: https://stackoverflow.com/questions/790 ... -to-fix-it
Мобильная версия