MrSfinx
@MrSfinx

Ошибка в Unity (c#), как исправить?

Делал по видео уроку, на видео всё работает, код перепроверял, совпадает.

Текст ошибки:

Assets\Scripts\GameControler.cs(48,21): error CS1061: 'GameObject' does not contain a definition for 'setVector' and no accessible extension method 'setVector' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?)

Вот в этой части кода возникает ошибка (без неё всё работает):

public GameObject cubeToCreate, allCubes;

 private void Update()
    {
        if (Input.GetMouseButtonDown(0) || Input.touchCount > 0)
        {
#if !UNITY_EDITOR
            if (Input.GetTouch(0).phase != TouchPhase.Began)
                return;
#endif
            GameObject newCube = Instantiate(
                cubeToCreate,
                cubeToPlase.position,
                Quaternion.identity) as GameObject;

            newCube.transform.SetParent(allCubes.transform);
            newCube.setVector(cubeToPlase.position);
            allCubesPositions.Add(nowCube.getVector());

            SpawnPositions();


        }

setVector вызывается отсюда:

struct CubePos
{
    public int x, y, z;

    public CubePos (int x, int y, 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);

    }
}
  • Вопрос задан
  • 213 просмотров
Решения вопроса 1
GavriKos
@GavriKos Куратор тега Unity
Видеоурок - туфта. Тут не может так работать. У вас newCube - GameObject, а не CubePos. А т.к. CubePos - структура (а не монобех например) - то даже сложно предположить где ошибка и что автор хотел этим кодом сказать.

Так что задавайте вопрос в комментарииях под видеоуроком
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы