1

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!

VicL
  • 69
  • 4

1 Answers1

-1

You are missing variable name in your for-loop:

 for (int i = 0; i < roomNumber, int++)
ˈvɔlə
  • 9,204
  • 10
  • 63
  • 89
  • 1
    Thank you! I specified the varible name as you suggested, although the frist one didn't appear to be problematic and it went all fine! Thank you very much again. – VicL Jan 02 '21 at 10:09
  • @VicL Why don't you just mark my answer as accepted? – ˈvɔlə Jan 05 '21 at 10:57