Files
Shopkeeper/Assets/Scripts/Items/ShelfInteraction.cs
Caleb Sandford deQuincey e9c9bc4409 initial game submission
2025-06-11 13:04:35 +01:00

46 lines
1.5 KiB
C#

using UnityEngine;
using System.Collections.Generic;
public class ShelfInteraction : MonoBehaviour
{
public Transform[] stackPoints; // Assign from Shelf or inspector
private List<GameObject> stackedItems = new List<GameObject>();
// 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;
}
}