@STrel564

Как исправить ошибку CS1061 в unity?

Привет всем! При программировании у меня вылезло пять ошибок CS1061:(

Первая:
Assets\SnakeMovement\Images\Scripts\SnakeManager.cs(41,57): error CS1061: 'MarkerManager' does not contain a definition for 'markerList' and no accessible extension method 'markerList' accepting a first argument of type 'MarkerManager' could be found (are you missing a using directive or an assembly reference?)

Вторая:
Assets\SnakeMovement\Images\Scripts\SnakeManager.cs(42,57): error CS1061: 'MarkerManager' does not contain a definition for 'markerList' and no accessible extension method 'markerList' accepting a first argument of type 'MarkerManager' could be found (are you missing a using directive or an assembly reference?)

Третья:
Assets\SnakeMovement\Images\Scripts\SnakeManager.cs(43,23): error CS1061: 'MarkerManager' does not contain a definition for 'markerList' and no accessible extension method 'markerList' accepting a first argument of type 'MarkerManager' could be found (are you missing a using directive or an assembly reference?)

Четвертая:
Assets\SnakeMovement\Images\Scripts\SnakeManager.cs(74,23): error CS1061: 'MarkerManager' does not contain a definition for 'markerList' and no accessible extension method 'markerList' accepting a first argument of type 'MarkerManager' could be found (are you missing a using directive or an assembly reference?)

Пятая:
Assets\SnakeMovement\Images\Scripts\SnakeManager.cs(75,23): error CS1061: 'MarkerManager' does not contain a definition for 'markerList' and no accessible extension method 'markerList' accepting a first argument of type 'MarkerManager' could be found (are you missing a using directive or an assembly reference?)
Пожалуйста помогите исправить! Заранее спасибо:)

Вот код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class SnakeManager : MonoBehaviour
{
    [SerializeField] float distanceBetween = .2f;
    [SerializeField] float speed = 280;
    [SerializeField] float turnSpeed = 18;
    [SerializeField] List<GameObject> bodyParts = new List<GameObject>();
    List<GameObject> snakeBody = new List<GameObject>();

    float countUp = 0;
    // Start is called before the first frame update
    void Start()
    {
        CreateBodyParts();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        if (bodyParts.Count > 0)
        {
            CreateBodyParts();
        }
        SnakeMovement();
    }
    void SnakeMovement()
    {

        snakeBody[0].GetComponent<Rigidbody2D>().velocity = snakeBody[0].transform.right * speed * Time.deltaTime;
        if (Input.GetAxis("Horizontal") != 0)
            snakeBody[0].transform.Rotate(new Vector3(0, 0, -turnSpeed * Time.deltaTime * Input.GetAxis("Horizontal")));        
    
        if(snakeBody.Count > 1)
        {
            for(int i = 1; i < snakeBody.Count; i++)
            {
                MarkerManager markM = snakeBody[i - 1].GetComponent<MarkerManager>();
                snakeBody[i].transform.position = markM.markerList[0].position; Ошибка 1
                snakeBody[i].transform.rotation = markM.markerList[0].rotation; Ошибка 2
                markM.markerList.RemoveAt(0); Ошибка 3
            }
        }
    
    
    }

    void CreateBodyParts()
    {
        if (snakeBody.Count == 0)
        {
            GameObject temp1 = Instantiate(bodyParts[0], transform.position, transform.rotation, transform);
            if (!temp1.GetComponent<MarkerManager>())
                temp1.AddComponent<MarkerManager>();
            if (!temp1.GetComponent<Rigidbody2D>())
            {
                temp1.AddComponent<Rigidbody2D>();
                temp1.GetComponent<Rigidbody2D>().gravityScale = 0;
            }
            snakeBody.Add(temp1);
            bodyParts.RemoveAt(0);
        }
        MarkerManager markM = snakeBody[snakeBody.Count - 1].GetComponent<MarkerManager>();
        if (countUp == 0)
        {
            markM.ClearMarkerList();
        }
        countUp += Time.deltaTime;
        if (countUp >= distanceBetween)
        {
            GameObject temp = Instantiate(bodyParts[0],
                markM.markerList[0].position, Ошибка 4
                markM.markerList[0].rotation, Ошибка 5
                transform);
            if (!temp.GetComponent<MarkerManager>())
                temp.AddComponent<MarkerManager>();
            if (!temp.GetComponent<Rigidbody2D>())
            {
                temp.AddComponent<Rigidbody2D>();
                temp.GetComponent<Rigidbody2D>().gravityScale = 0;
            }
            snakeBody.Add(temp);
            bodyParts.RemoveAt(0);
            temp.GetComponent<MarkerManager>().ClearMarkerList();
            countUp = 0;
        }
    }
}
  • Вопрос задан
  • 975 просмотров
Решения вопроса 1
vabka
@vabka
Токсичный шарпист
В классе MarkerManager нет публичного поля или свойства markerList.
Либо добавь его, либо сделай его публичным, либо исправь опечатку.
Ну и раз ты уже на таких моментах спотыкаешься - лучше начни с консольных приложений, а потом вернись к юнити.
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

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

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