如何在我的 2D roguelike 地牢游戏中修复此程序生成代码中的 CS1525 错误?

时间:2021-01-02 08:25:22

标签: c# unity3d procedural-generation roguelike

Unity C# 编码的新手。我正在编写一个脚本来在 2D roguelike 游戏中实现程序生成。我的想法是使用 enum 表示 4 个方向(上、下、左、右),然后选择一个随机方向从 Prefab 生成一个房间。然后下一个房间将通过相同的方法生成。这是我的代码:

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

public class RoomGenerator : MonoBehaviour
{
    public enum Direction { up, down, left, right };
    public Direction direction;
    [Header("Room Information")]
    public GameObject roomPrefab;
    public int roomNumber;
    public Color startColor, endColor;

    [Header("Position Controller")]
    public Transform generatorPoint;
    public float xOffset;
    public float yOffset;
    public List<GameObject> rooms = new List<GameObject>();


    void Start()
    {
        for (int = 0; i < roomNumber, int++)
        {
            rooms.Add(Instantiate(roomPrefab, transform.position, Quaternion.identity));
            ChangePointPosition();
        }

    }


    void Update()
    {
        
    }

    public void ChangePointPosition()
    {
        direction = (Direction)Random.Range(0,4);

        switch(direction)
        {
            case Direction.up:
                generatorPoint.position += new Vector3 (0, yOffset, 0);
                break;
            case Direction.down:
                generatorPoint.position += new Vector3 (0, -yOffset, 0);
                break;
            case Direction.left:
                generatorPoint.position += new Vector3 (-xOffset, 0, 0);
                break;
            case Direction.right:
                generatorPoint.position += new Vector3 (xOffset, 0, 0);
                break;
        }
    }
}

Unity 说“错误 CS1525:无效的表达式术语‘int’”。这怎么可能?我错过了什么?请帮忙。提前致谢!

1 个答案:

答案 0 :(得分:-2)

您的 for 循环中缺少变量名称:

 for (int i = 0; i < roomNumber, int++)
相关问题