using UnityEngine; using Bekkoloco.QuickTile; public class DigBlockSpawner : MonoBehaviour { public QuickTilemapEditor level; // Put this marker at the centre of the block's top face. // When empty, Spawn uses this GameObject's position. public Transform topCenter; // Zero-based index in level.tileRules, not the Paths list. [Min(0)] public int ruleIndex = 0; // World-space dimensions in metres: width, depth, length. public Vector3 worldSize = Vector3.one; private string lastVolumeId; [ContextMenu("Spawn dig block")] public void Spawn() { Vector3 position = topCenter != null ? topCenter.position : transform.position; SpawnAt(position); } // Call this from another script to choose the position at runtime. public QuickTileDigVolume SpawnAt(Vector3 worldTopCenter) { if (level == null) { Debug.LogWarning("Assign the QuickTile level first.", this); return null; } var volume = level.CreateDigVolume( worldTopCenter, worldSize, ruleIndex); if (volume == null) { Debug.LogWarning( "Choose a diggable terrain rule with Dig Mode " + "set to Volume or Both.", this); return null; } lastVolumeId = volume.persistentId; return volume; } [ContextMenu("Fill last dig block")] public void FillLast() { if (level == null || string.IsNullOrEmpty(lastVolumeId)) return; if (level.RemoveDigVolume(lastVolumeId)) lastVolumeId = null; } }