Форум программистов, компьютерный форум, киберфорум
Unity, Unity3D
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.62/13: Рейтинг темы: голосов - 13, средняя оценка - 4.62
0 / 0 / 0
Регистрация: 27.06.2021
Сообщений: 2
1

CS1061: 'GameObject' does not contain a definition for 'transfrom' and no accessible extension method 'transfrom'

28.06.2021, 10:15. Показов 2502. Ответов 1

Author24 — интернет-сервис помощи студентам
Здравствуйте, создаю впервые тему на данном сайте, надеюсь, что ничего не напутал в заголовке и метках. Стоит заранее сказать, что я новичок в C# и Unity и изучать их начал относительно недавно. Я столкнулся с ошибкой указанной в заголовке во время своей попытки создать игру на Unity. Полный ( на всякий случай ) код прикладываю ниже ( также отмечу (//) место где и появляется ошибка ):

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
 
public class GameController : MonoBehaviour
{
    private CubePos nowCube = new CubePos(0,1,0);
    public float cubeChangePlaceSpeed = 0.5f;
    public Transform cubeToPlace;
 
    public GameObject cubeToCreate, allCubes;
 
    private List<Vector3> allCubesPositions = 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,1),
        new Vector3 (0,0,-1),
        new Vector3 (1,0,1),
        new Vector3 (-1,0,-1),
        new Vector3 (-1,0,1),
        new Vector3 (1,0,-1),
    };
 
    private void Start()
    {
        StartCoroutine(ShowCubePlace());
    }
    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,
                cubeToPlace.position,
                Quaternion.identity) as GameObject;
 
            newCube.transform.SetParent(allCubes.transfrom); // Именно внутри скобочек выдаёт ошибку.
            nowCube.setVector(cubeToPlace.position);
            allCubesPositions.Add(nowCube.getVector());
 
            SpawnPositions();
        }
    }
 
    IEnumerator ShowCubePlace()
    {
        while (true)
        {
            SpawnPositions();
 
            yield return new WaitForSeconds(cubeChangePlaceSpeed);
        }
    }
    private void SpawnPositions()
    {
        List<Vector3> positions = new List<Vector3>();
        if (IsPositionEmpty(new Vector3(nowCube.x + 1, nowCube.y, nowCube.z)) && nowCube.x + 1 != cubeToPlace.position.x)
            positions.Add(new Vector3(nowCube.x + 1, nowCube.y, nowCube.z));
        if (IsPositionEmpty(new Vector3(nowCube.x - 1, nowCube.y, nowCube.z)) && nowCube.x - 1 != cubeToPlace.position.x)
                positions.Add(new Vector3(nowCube.x - 1, nowCube.y, nowCube.z));
        if (IsPositionEmpty(new Vector3(nowCube.x, nowCube.y + 1, nowCube.z)) && nowCube.y + 1 != cubeToPlace.position.y)
            positions.Add(new Vector3(nowCube.x, nowCube.y + 1, nowCube.z));
        if (IsPositionEmpty(new Vector3(nowCube.x, nowCube.y - 1, nowCube.z)) && nowCube.y - 1 != cubeToPlace.position.y)
            positions.Add(new Vector3(nowCube.x, nowCube.y - 1, nowCube.z));
        if (IsPositionEmpty(new Vector3(nowCube.x, nowCube.y, nowCube.z + 1)) && nowCube.z + 1 != cubeToPlace.position.z)
            positions.Add(new Vector3(nowCube.x, nowCube.y, nowCube.z + 1));
        if (IsPositionEmpty(new Vector3(nowCube.x + 1, nowCube.y, nowCube.z - 1)) && nowCube.z - 1 != cubeToPlace.position.z)
            positions.Add(new Vector3(nowCube.x, nowCube.y, nowCube.z - 1));
 
        cubeToPlace.position = positions[UnityEngine.Random.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;
    }
}
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);
 
    }
}
0
Лучшие ответы (1)
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
28.06.2021, 10:15
Ответы с готовыми решениями:

UNITY error CS1061: 'Slider' does not contain a definition for 'Value' and no accessible extension method 'Value' ac
Помогите не понимаю как исправить ошибку. error CS1061: 'Slider' does not contain a definition for...

List<Student>' does not contain a definition for 'StudentName' and no extension method
Получаю такую ошибку при попытке вывода View: 'List&lt;Student&gt;' does not contain a definition for...

Ошибка: Window does not contain a definition for 'Controls' and no extension method 'Controls'
Решил заняться c#, но что-то не могу разобраться. имеется некоторое количество textBox'ов...

Ошибка error CS1061: 'Rigidbody' does not contain a definition for 'velicity'
Пишу скрипт что бы двигался кубик, и вылезает ошибка:Assets\Player.cs(20,39): error CS1061:...

1
2638 / 1566 / 853
Регистрация: 23.02.2019
Сообщений: 3,876
28.06.2021, 11:27 2
Лучший ответ Сообщение было отмечено DoradoS как решение

Решение

У вас опечатка, вместо
transfrom
нужно
transform
1
28.06.2021, 11:27
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
28.06.2021, 11:27
Помогаю со студенческими работами здесь

ошибка error CS1061: 'Transform' does not contain a definition for 'eulerAngels' and no
делал чтобы персонаж поворачивался и выскочила ошибка, в чем проблема может быть? using...

Error Inconsistent accessibility: parameter ...is less accessible than method ...
Есть 3 класса. Первые 2 реализуют 1 интерфеис. Третии клас - тестирует работу первых двух. Хочу...

Ошибка компиляции CS0051: Inconsistent accessibility: parameter type is less accessible than method
Моя задача, заполнить List&lt;type&gt; в методе. Делаю так: public class Human { public...

Как получить из кода GameObject, прикреплённый к другому GameObject?
Суть- есть GameObject enemy, классика. Есть GameObject ObjectHandler, пустышка, чьё...

Внутри GameObject создать новый GameObject
Как из скрипта (C#) внутри GameObject создать новый GameObject?


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
2
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru