@flessska

Ошибка в юнити «error CS1022: Type or namespace definition, or end-of-file expected»?

В чем заключается проблема ?

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

public class GameController : MonoBehaviour
{
    struct CubePos(0, 1, 0);
public float cubeChangePlaceSpeed = 0.5f;
    public Transform cubeToPlace
        }

private List<Vector3> allCubesPosition = new List<Vector3>
{
    new Vector3(0, 0, 0),
    new Vector3(1, 0, 0),
    new Vector3(-1, 0, 0),
    new Vector3(0, 1, 0),
    new Vector3(0, 0, 0),
    new Vector3(-1, 0, -1),
    new Vector3(1, 0, 1),
    new Vector3(0, 0, -1),
    new Vector3(1, 0, -1),
}
private void Start()
{
    StartCoroutine(ShowCubePlace());
}

IEnumerator ShowCubePlace()
{
    while(true)
    {
        SpawnPosition();

        yield return new WaitForSeconds(cubeChangePlaceSpwwd)
    }
}


private void SpawnPosition()
{
    List<Vector3> position = new List<Vector3>();
    if (IsPositionEmpty(new Vector3(nowCube.x + 1, nowCube.y, nowCube.z)))
        position.Add(new Vector3(nowCube.x + 1, nowCube.y, nowCube.z));
    if (IsPositionEmpty(new Vector3(nowCube.x - 1, nowCube.y, nowCube.z)))
        position.Add(new Vector3(nowCube.x - 1, nowCube.y, nowCube.z));
    if (IsPositionEmpty(new Vector3(nowCube.x, nowCube.y + 1, nowCube.z)))
        position.Add(new Vector3(nowCube.x, nowCube.y + 1, nowCube.z));
    if (IsPositionEmpty(new Vector3(nowCube.x, nowCube.y - 1, nowCube.z)))
        position.Add(new Vector3(nowCube.x, nowCube.y - 1, nowCube.z));
    if (IsPositionEmpty(new Vector3(nowCube.x, nowCube.y, nowCube.z + 1)))
        position.Add(new Vector3(nowCube.x, nowCube.y, nowCube.z + 1));
    if (IsPositionEmpty(new Vector3(nowCube.x, nowCube.y, nowCube.z - 1)))
        position.Add(new Vector3(nowCube.x, nowCube.y, nowCube.z - 1));

    cubeToPlace.position = position[UnityEngineRandom.Range(0, positions.Count)]
        }


private bool IsPositionEmpty(Vector3 targetPos)
{
    if (targetPos.y == 0)
        return false;

    foreach(Vector3 pos in allCubesPositions)
    {
        if (pos.x == targetPos.x && pos.y == targetPos.y && pos.z == targetPos.z)
            return false;
    }

    return true;

}
    public int x, y, z;
{

    public CubePos(int x, int z, int z)
    {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    public Vector3 getVector()
    {
        return new Vector3(x, y, z);
    }

    public void setVector(Vector3 pos)
    {
        x = Convert.ToInt32(pos.x);
        y = Convert.ToInt32(pos.y);
        z = Convert.ToInt32(pos.z);
    }

}
  • Вопрос задан
  • 1360 просмотров
Пригласить эксперта
Ответы на вопрос 1
Ошибка в том, что ты криво скопировал код, и объявление структуры struct CubePos отделилось от определения.

Вот попытался исправить:
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

public class GameController: MonoBehaviour {
	public float cubeChangePlaceSpeed = 0.5f;
	public Transform cubeToPlace;
	private List<Vector3> allCubesPosition = new List {
		new Vector3(0, 0, 0),
		new Vector3(1, 0, 0),
		new Vector3(-1, 0, 0),
		new Vector3(0, 1, 0),
		new Vector3(0, 0, 0),
		new Vector3(-1, 0, -1),
		new Vector3(1, 0, 1),
		new Vector3(0, 0, -1),
		new Vector3(1, 0, -1),
	}
	private void Start() {
		StartCoroutine(ShowCubePlace());
	}

	IEnumerator ShowCubePlace() {
		while (true) {
			SpawnPosition();
			yield return new WaitForSeconds(cubeChangePlaceSpwwd)
		}
	}

	private void SpawnPosition() {
		List position = new List();
		if (IsPositionEmpty(new Vector3(nowCube.x + 1, nowCube.y, nowCube.z))) position.Add(new Vector3(nowCube.x + 1, nowCube.y, nowCube.z));
		if (IsPositionEmpty(new Vector3(nowCube.x - 1, nowCube.y, nowCube.z))) position.Add(new Vector3(nowCube.x - 1, nowCube.y, nowCube.z));
		if (IsPositionEmpty(new Vector3(nowCube.x, nowCube.y + 1, nowCube.z))) position.Add(new Vector3(nowCube.x, nowCube.y + 1, nowCube.z));
		if (IsPositionEmpty(new Vector3(nowCube.x, nowCube.y - 1, nowCube.z))) position.Add(new Vector3(nowCube.x, nowCube.y - 1, nowCube.z));
		if (IsPositionEmpty(new Vector3(nowCube.x, nowCube.y, nowCube.z + 1))) position.Add(new Vector3(nowCube.x, nowCube.y, nowCube.z + 1));
		if (IsPositionEmpty(new Vector3(nowCube.x, nowCube.y, nowCube.z - 1))) position.Add(new Vector3(nowCube.x, nowCube.y, nowCube.z - 1));

		cubeToPlace.position = position[UnityEngineRandom.Range(0, positions.Count)]
	}

	private bool IsPositionEmpty(Vector3 targetPos) {
		if (targetPos.y == 0) return false;

		foreach(Vector3 pos in allCubesPositions) {
			if (pos.x == targetPos.x && pos.y == targetPos.y && pos.z == targetPos.z) return false;
		}

		return true;
	}
}
// CubePos удалил, тк он не используется, и смысла в нём нет
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы