Search code examples
c#unity-game-engineprocedural-generationroguelike

How do I fix CS1525 error in this procedural generation code in my 2D roguelike dungeon game?


New to Unity C# coding. I'm writing a script to achieve procedural generation in a 2D roguelike game. My idea is to use enum to represent 4 directions (up, down, left, right), then pick a random direction to produce a room from Prefab. Then next room will be generated by the same method. Here are my codes:

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 is saying "error CS1525: invalid expression term 'int'". How's that possible? Did I miss something? Please help. Thanks in advance!


Solution

  • You are missing variable name in your for-loop:

     for (int i = 0; i < roomNumber, int++)