#Output codes halfway stoped

4 messages · Page 1 of 1 (latest)

calm sail
#

My input:
Assets\scripts\Chessboard.cs(107,2): error CS1513: } expected with the following code: using System;
using UnityEngine;
using UnityEngine.Serialization;

public class Chessboard : MonoBehaviour
{
[Header("Art")]
[SerializeField] private Material tileMaterial;

//Logic
private const int TILE_COUNT_X = 8;
private const int TILE_COUNT_Y = 8;
private GameObject[,] tiles;
private Camera currentCamera;
private Vector2Int currentHover = -Vector2Int.one;

private void Awake()
{
    GenerateAllTiles(1, TILE_COUNT_X, TILE_COUNT_Y);
}

private void Update()
{
    if (!currentCamera)
    {
        currentCamera = Camera.current;
        return;
    }

    RaycastHit info;
    Ray ray = currentCamera.ScreenPointToRay(Input.mousePosition);
    if (Physics.Raycast(ray, out info, 100, LayerMask.GetMask("Tile")))
    {
        // get the indexes of Tile i've hit 
        Vector2Int hitPosition = LookupTileIndex(info.transform.gameObject);

        //If we are hovering a tile after not hovering any
        if (currentHover == -Vector2Int.one)
        {
            tiles[hitPosition.x, hitPosition.y].layer = LayerMask.NameToLayer("Hover");
            currentHover = hitPosition;
        }
        //If we were already hovering a tile, change the previous one
        else if (currentHover != hitPosition)
        {
            tiles[currentHover.x, currentHover.y].layer = LayerMask.NameToLayer("Tile");
            currentHover = hitPosition;
            tiles[hitPosition.x, hitPosition.y].layer = LayerMask.NameToLayer("Hover");
        }
    }
    else
    {
        if (currentHover != -Vector2Int.one)
        {
            tiles[currentHover.x, currentHover.y].layer = LayerMask.NameToLayer("Tile");
            currentHover = -Vector2Int.one;
        }
    }
}

//Generate the board (useful)
private void GenerateAllTiles(float tileSize, int tileCountX, int tileCountY)

{
tiles = new GameObject[tileCountX, tileCountY];
for (int x = 0; x < tileCountX; x++)
for (int y = 0; y < tileCountY; y++)
tiles[x, y] = generate1tile(tileSize, x, y);
}

private GameObject generate1tile(float tileSize, int x, int y)
{
GameObject tileObject = new GameObject(string.Format("Tile X:{0}, Y:{1}", x, y));
tileObject.transform.parent = transform;

Mesh mesh = new Mesh();
tileObject.AddComponent<MeshFilter>().mesh = mesh;

tileObject.AddComponent<MeshRenderer>().material = tileMaterial;

Vector3[] vertices = new Vector3[4];
vertices[0] = new Vector3(x * tileSize, 0, y * tileSize);
vertices[1] = new Vector3(x * tileSize, 0, (y + 1) * tileSize);
vertices[2] = new Vector3((x + 1) * tileSize, 0, y * tileSize);
vertices[3] = new Vector3((x + 1) * tileSize, 0, (y + 1) * tileSize);

int[] tris = new int[]{0, 2, 1, 1, 2, 3};

mesh.vertices = vertices;
mesh.triangles = tris;

mesh.RecalculateNormals();
tileObject.layer = LayerMask.NameToLayer("Tile");
tileObject.AddComponent<BoxCollider>();

return tileObject;

}

private Vector2Int LookupTileIndex(GameObject hitInfo)
{
for(int x = 0; x < TILE_COUNT_X; x++)
for(int y = 0; y < TILE_COUNT_Y; y++)
if(tiles[x, y] == hitInfo)
return new Vector2Int(x, y);

return new Vector2Int(-1, -1); //Invalid 

}

#

Ai output:
It seems like you have an extra opening brace "{" before the GenerateAllTiles method, and it's missing the closing brace "}" at the end of the code.

Try this code instead:

csharp
Copy code
using System;
using UnityEngine;
using UnityEngine.Serialization;

public class Chessboard : MonoBehaviour
{
[Header("Art")]
[SerializeField] private Material tileMaterial;

//Logic
private const int TILE_COUNT_X = 8;
private const int TILE_COUNT_Y = 8;
private GameObject[,] tiles;
private Camera currentCamera;
private Vector2Int currentHover = -Vector2Int.one;

private void Awake()
{
    GenerateAllTiles(1, TILE_COUNT_X, TILE_COUNT_Y);
}

private void Update()
{
    if (!currentCamera)
    {
        currentCamera = Camera.current;
        return;
    }

    RaycastHit info;
    Ray ray = currentCamera.ScreenPointToRay(Input.mousePosition);
    if (Physics.Raycast(ray, out info, 100, LayerMask.GetMask("Tile")))
    {
        // get the indexes of Tile i've hit 
        Vector2Int hitPosition = LookupTileIndex(info.transform.gameObject);

        //If we are hovering a tile after not hovering any
        if (currentHover == -Vector2Int.one)
        {
            tiles[hitPosition.x, hitPosition.y].layer = LayerMask.NameToLayer("Hover");
            currentHover = hitPosition;
        }
        //If we were already hovering a tile, change the previous one
        else if (currentHover != hitPosition)
        {
            tiles[currentHover.x, currentHover.y].layer = LayerMask.NameToLayer("Tile");
            currentHover = hitPosition;
            tiles[hitPosition.x, hitPosition.y].layer = LayerMask.NameToLayer("Hover");
        }
    }
    else
    {
        if (currentHover != -Vector2Int.one)
        {
            tiles[currentHover.x, currentHover.y].layer = LayerMask.NameToLayer("Tile");
            currentHover = -Vector2Int.one;
        }
    }
}

//Generate the board (useful)
private void GenerateAllTiles(float tileSize, int tileCountX, int tileCountY)
{
    tiles = new GameObject[tileCountX, tileCountY];
    for (int x = 0; x < tileCountX; x++)
        for (int y = 0; y < tileCountY; y++)
            tiles[x, y] = generate1tile(tileSize, x, y);
}

private GameObject generate1tile(float tileSize, int x, int y)
{
    GameObject tileObject = new GameObject(string.Format("Tile X:{0}, Y:{1}", x, y));
    tileObject.transform.parent = transform;

    Mesh mesh = new Mesh();
    tileObject.AddComponent<MeshFilter>().mesh = mesh;

It just stop there, idk why, need help with it

mellow shale
#

Same here! I thought the ChatGPT Plus subscription would fix it, but no.

lusty mortar
#

Indeed, just renders the functionality as useless. There is a max of 2048 characters