Name does not exist in the current context error in C# Unity

问题描述 投票:0回答:1

在 ProceduralGenerationAlgorithms 函数中,我遇到了错误:当前上下文中不存在名称“ProceduralGenerationAlgorithms”。这是我的代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using Random = UnityEngine.Random;

public class NewBehaviourScript : MonoBehaviour
{
    [SerializeField]
    protected Vector2Int startPosition = Vector2Int.zero;
    
     [SerializeField]
    private int iterations = 10;
    
    [SerializeField]
    public int walkLength = 10;
    
    [SerializeField]
    public bool startRandomlyEachIteration = true;

    public void  RunProceduralGeneration()
    {
        HashSet<Vector2Int> floorPositions = RunRandomWalk(); 
        foreach (var position in floorPositions)
        {
            Debug.Log(position);
        } 
    }

    protected HashSet<Vector2Int> RunRandomWalk()
    
    {
        var currentPosition = startPosition;
        HashSet<Vector2Int> floorPositions = new HashSet<Vector2Int>();
        for (int i = 0; i <iterations; i++)
        {
            var path = ProceduralGenerationAlgorithms.SimpleRandomWalk(currentPosition, walkLength);
            floorPositions.UnionWith(path);
            if(startRandomlyEachIteration)
                currentPosition = floorPositions.ElementAt(Random.Range(0,floorPositions.Count));
        }
        return floorPositions;
    }
}

我只是想按照教程中的说明进行操作

https://www.youtube.com/watch?v=LnbZLnCXSyI&list=PLcRSafycjWFenI87z7uZHFv6cUG2Tzu9v&index=6

c# unity3d game-development
1个回答
0
投票

没有看您链接的视频,但看来您需要自己实现该算法。可能这个github链接来自你的教程。

© www.soinside.com 2019 - 2024. All rights reserved.