#lets take this into dms so other people

1 messages · Page 1 of 1 (latest)

manic pier
#

No dms please

#

can use the thread if you want

#

You also don't need to dump all your scripts

#

Your issue is readily apparent in the code you already shared

oak patrol
#

its just the 2

#

Global.cs ```cs
public class Global : MonoBehaviour
{
public static GameTilePreset[] GameTilePresets;
public static GameTile[] GameTiles;

public static GameTile GetTile(Vector2 Position) {
    if (Position.y <= -2) {
        GameTile Floor = GameTile.CreateInstance<GameTile>();
        Floor.Preset.ConnectUp = true;
        return Floor;
    }

    for (int i = 0; i < GameTiles.Length; i++) {
        if (GameTiles[i].Position == Position) { 
            return GameTiles[i];
        }
    }
    return null;
}

}

#

Selector.cs ```cs
public class Selector : MonoBehaviour
{
public Vector3 Offset = new Vector3(0,0,0);
void Update()
{
Vector3 Pos = Input.mousePosition;
Camera Cam = Camera.main;
Pos = Cam.ScreenToWorldPoint(Pos);
Pos.x = Mathf.Round(Pos.x) + Offset.x;
Pos.y = Mathf.Round(Pos.y) + Offset.y;
Pos.z = Offset.z;
transform.position = Pos;

    Pos.y -= 1;
    GameTile? Tile = Global.GetTile((Vector2)Pos);

    if (Tile.Preset != null)
    {
        if (Tile.Preset.ConnectUp == true)
        {
            gameObject.GetComponent<SpriteRenderer>().color = new Color(0, 255, 0, 125);
        } else {
            gameObject.GetComponent<SpriteRenderer>().color = new Color(255, 0, 0, 125);
        }
    } else {
        gameObject.GetComponent<SpriteRenderer>().color = new Color(255, 0, 0, 125);
    }
}

}

#

i need to acess the GetTile function in the Global.cs script

manic pier
#

yeah

#

you're doing that

#

the problem is you never created your arrays

oak patrol
#
public static GameTilePreset[] GameTilePresets = { };
public static GameTile[] GameTiles = { };
#

?

manic pier
#

sure you can do that

#

but now they're just empty arrays

#

they certainly won't contain any data

oak patrol
#

same errors

manic pier
#

you sure

#

show the error

#

i bet it's a different error now

oak patrol
manic pier
#

that's different

#

Selector.cs, line 22

#

That's this gameObject.GetComponent<SpriteRenderer>().color = new Color(0, 255, 0, 125);

oak patrol
manic pier
#

that means that you don't have a SpriteRenderer attached to the same GameObject as your Selector script

#

there's also a lot of other problems with that line but we'll skip that for now...

oak patrol
#

line 22: cs if (Tile.Preset != null)

manic pier
#

Tile is null

#

you can't do Tile.Preset if Tile is null

oak patrol
#
if (Tile == null) return;
manic pier
#

where is that

#

that's not in the code you shared

oak patrol
#

adding it

manic pier
#

show the updated code

oak patrol
#

only 1 of the 2 errors shows now

manic pier
#

and what line that is

oak patrol
#
public class Selector : MonoBehaviour
{
    public Vector3 Offset = new Vector3(0,0,0);
    void Update()
    {
        Vector3 Pos = Input.mousePosition;
        Camera Cam = Camera.main;
        Pos = Cam.ScreenToWorldPoint(Pos);
        Pos.x = Mathf.Round(Pos.x) + Offset.x;
        Pos.y = Mathf.Round(Pos.y) + Offset.y;
        Pos.z = Offset.z;
        transform.position = Pos;

        Pos.y -= 1;
        GameTile? Tile = Global.GetTile((Vector2)Pos);
        if (Tile == null) return;
        if (Tile.Preset != null)
        {
            if (Tile.Preset.ConnectUp == true)
            {
                gameObject.GetComponent<SpriteRenderer>().color = new Color(0, 255, 0, 125);
            } else {
                gameObject.GetComponent<SpriteRenderer>().color = new Color(255, 0, 0, 125);
            }
        } else {
            gameObject.GetComponent<SpriteRenderer>().color = new Color(255, 0, 0, 125);
        }
    }
}
manic pier
#

note we're still quite far from this working, because you're missing a lot still

oak patrol
#

oh i see the error

#

i think i know how 2 fix it

#

FIXED

#

LETS GOOOO

#

replaced

if (Position.y <= -2) {
            GameTile Floor = GameTile.CreateInstance<GameTile>();
            Floor.Preset.ConnectUp = true;
            return Floor;
        }

with

        if (Position.y <= -2) {
            GameTile Floor = GameTile.CreateInstance<GameTile>();
            Floor.Preset = GameTilePreset.CreateInstance<GameTilePreset>();
            Floor.Preset.ConnectUp = true;
            return Floor;
        }