Files
Shopkeeper/Assets/Scripts/Items/Crate.cs
Caleb Sandford deQuincey 47944971ca initial game submission
2025-06-10 22:13:25 +01:00

27 lines
683 B
C#

using UnityEngine;
public class Crate : MonoBehaviour
{
public void OpenCrate()
{
// Detach all child items and enable their physics
foreach (Transform child in transform)
{
child.SetParent(null);
Rigidbody rb = child.GetComponent<Rigidbody>();
if (rb != null)
{
rb.isKinematic = false;
rb.AddForce(Vector3.up * 2f + Random.insideUnitSphere, ForceMode.Impulse);
}
}
// Optionally destroy the crate object
//Destroy(gameObject);
}
// Example: Open crate on mouse click
void UnpackCrate()
{
OpenCrate();
}
}