I am trying to figure out what was figured out in this thread (Using Tiled Custom Properties with SuperTiled2Unity) which for some reason just I cannot make sense of.
Basically I just want to be able to check in Unity if a tile has the “Walkable” custom property as true before they move to it. I want to only be able to move to tiles that have this as true.
Basically I want to include some logic in the movement script for this tile selector, so it can only scroll around or move around on the “Walkable” tiles from Tiled using SuperTiled2Unity. Right now I have the movement logic for the Tile Selector functioning, as far as it will move from tile to tile in the way I want, but can move outside the grass onto the water etc etc. Everything I try from that other thread doesnt seem to work for me.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;
using SuperTiled2Unity; // Include the SuperTiled2Unity namespace
public class TileSelector : MonoBehaviour
{
public float tileWidth = 0.5f; // Width of each tile
public float tileHeight = 0.25f; // Height of each tile
private Vector3 selectorPosition;
public float moveDelay = 0.15f; // Delay between moves to prevent too-fast movement
public Tilemap tilemaps; // Array to hold multiple Tilemaps
private float timeSinceLastMove = 0f;
// Start is called before the first frame update
void Start()
{
// Start the selector at the correct position
selectorPosition = transform.position;
}
// Update is called once per frame
void Update()
{
timeSinceLastMove += Time.deltaTime;
if (timeSinceLastMove >= moveDelay)
{
// Get direction from input, normalized for consistent movement speed
Vector2 direction = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")).normalized;
if (direction.x != 0 || direction.y != 0)
{
// Initialize movement values
float moveX = 0f;
float moveY = 0f;
// Determine movement direction based on input
if (direction.y > 0) // Up
{
moveX = 0.5f; // Move 0.5 on X
moveY = 0.25f; // Move 0.25 on Y
}
else if (direction.y < 0) // Down
{
moveX = -0.5f; // Move -0.5 on X
moveY = -0.25f; // Move -0.25 on Y
}
else if (direction.x < 0) // Right
{
moveX = -0.5f; // Move -0.5 on X
moveY = 0.25f; // Move 0.25 on Y
}
else if (direction.x > 0) // Left
{
moveX = 0.5f; // Move 0.5 on X
moveY = -0.25f; // Move -0.25 on Y
}
// Update selector position
selectorPosition.x += moveX;
selectorPosition.y += moveY;
// Snap the selector to the isometric grid
transform.position = new Vector3(
Mathf.Round(selectorPosition.x / tileWidth) * tileWidth,
Mathf.Round(selectorPosition.y / tileHeight) * tileHeight,
transform.position.z);
// Reset the timer after movement
timeSinceLastMove = 0f;
}
}
}
}
`type or paste code here`