using UnityEngine; using System.Collections.Generic; public class ShelfInteraction : MonoBehaviour { public Transform[] stackPoints; // Assign from Shelf or inspector private List stackedItems = new List(); // Try to stack an item at a specific stack point index public bool TryStackItem(GameObject item, int stackPointIndex) { if (stackPointIndex < 0 || stackPointIndex >= stackPoints.Length) return false; // Check if the stack point is already occupied foreach (var stacked in stackedItems) { if (stacked != null && stacked.transform.position == stackPoints[stackPointIndex].position) return false; // Occupied } // Place the item item.transform.position = stackPoints[stackPointIndex].position; item.transform.rotation = stackPoints[stackPointIndex].rotation; stackedItems.Add(item); return true; } // Call this when removing or spoiling an item public void RemoveStackedItem(GameObject item) { if (stackedItems.Contains(item)) stackedItems.Remove(item); } // For ghost preview: returns true if the stack point is occupied public bool IsStackPointOccupied(int stackPointIndex) { foreach (var stacked in stackedItems) { if (stacked != null && stacked.transform.position == stackPoints[stackPointIndex].position) return true; } return false; } }