아이템 드랍 및 인벤토리 기능 구현
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using NUnit.Framework.Interfaces;
|
||||
using System.Collections;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class MineableBlock : NetworkBehaviour
|
||||
{
|
||||
@@ -9,6 +10,8 @@ public class MineableBlock : NetworkBehaviour
|
||||
// [동기화] 모든 플레이어가 동일한 블록 체력을 보게 함
|
||||
private NetworkVariable<int> _currentHp = new NetworkVariable<int>();
|
||||
|
||||
[SerializeField] private ItemData dropItemData;
|
||||
[SerializeField] private GameObject genericDropPrefab; // 여기에 위에서 만든 'GenericDroppedItem' 프리팹을 넣으세요.
|
||||
|
||||
[Header("Visuals")]
|
||||
private Outline _outline;
|
||||
@@ -60,6 +63,7 @@ public class MineableBlock : NetworkBehaviour
|
||||
|
||||
private void DestroyBlock()
|
||||
{
|
||||
DropItem();
|
||||
// 2. 서버에서 네트워크 오브젝트 제거 (모든 클라이언트에서 사라짐)
|
||||
GetComponent<NetworkObject>().Despawn();
|
||||
}
|
||||
@@ -84,8 +88,6 @@ public class MineableBlock : NetworkBehaviour
|
||||
private IEnumerator ShakeRoutine()
|
||||
{
|
||||
float elapsed = 0.0f;
|
||||
Debug.Log("흔들림 코루틴 시작"); // 시작 확인
|
||||
|
||||
while (elapsed < shakeDuration)
|
||||
{
|
||||
Vector3 randomOffset = Random.insideUnitSphere * shakeMagnitude;
|
||||
@@ -99,6 +101,22 @@ public class MineableBlock : NetworkBehaviour
|
||||
}
|
||||
|
||||
transform.localPosition = _originalPos;
|
||||
Debug.Log("흔들림 코루틴 종료 및 위치 복구");
|
||||
}
|
||||
|
||||
private void DropItem()
|
||||
{
|
||||
if (!IsServer || dropItemData == null || genericDropPrefab == null) return;
|
||||
|
||||
// 원본 블록이 아니라 '범용 컨테이너'를 소환합니다.
|
||||
GameObject dropObj = Instantiate(genericDropPrefab, transform.position + Vector3.up * 0.5f, Quaternion.identity);
|
||||
|
||||
NetworkObject netObj = dropObj.GetComponent<NetworkObject>();
|
||||
netObj.Spawn();
|
||||
|
||||
// 소환된 컨테이너에 "너는 어떤 아이템의 모양을 따라해야 해"라고 알려줍니다.
|
||||
if (dropObj.TryGetComponent<DroppedItem>(out var droppedItem))
|
||||
{
|
||||
droppedItem.Initialize(dropItemData.itemID);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user