#lets take this into dms so other people
1 messages · Page 1 of 1 (latest)
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
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
public static GameTilePreset[] GameTilePresets = { };
public static GameTile[] GameTiles = { };
?
sure you can do that
but now they're just empty arrays
they certainly won't contain any data
same errors
that's different
Selector.cs, line 22
That's this gameObject.GetComponent<SpriteRenderer>().color = new Color(0, 255, 0, 125);
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...
line 22: cs if (Tile.Preset != null)
if (Tile == null) return;
show the updated code
only 1 of the 2 errors shows now
and what line that is
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);
}
}
}
note we're still quite far from this working, because you're missing a lot still
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;
}