블록 조준 시스템 제작

및 기본 에디터 자동 호스트화
This commit is contained in:
2026-01-17 14:32:05 +09:00
parent b6822691b6
commit 11b9112739
36 changed files with 2644 additions and 36 deletions

View File

@@ -1,5 +1,6 @@
using UnityEngine;
using Unity.Netcode;
using UnityEngine;
using System.Collections;
public class MineableBlock : NetworkBehaviour
{
@@ -8,8 +9,32 @@ public class MineableBlock : NetworkBehaviour
// [동기화] 모든 플레이어가 동일한 블록 체력을 보게 함
private NetworkVariable<int> _currentHp = new NetworkVariable<int>();
[Header("Visuals")]
[SerializeField] private GameObject breakEffectPrefab; // 파괴 시 파티클
private Outline _outline;
private Vector3 _originalPos;
[Header("Shake Settings")]
[SerializeField] private float shakeDuration = 0.15f; // 흔들리는 시간
[SerializeField] private float shakeMagnitude = 0.1f; // 흔들리는 강도
private Coroutine _shakeCoroutine;
void Awake()
{
// 해당 오브젝트 혹은 자식에게서 Outline 컴포넌트를 찾습니다.
_outline = GetComponentInChildren<Outline>();
_originalPos = transform.localPosition; // 로컬 위치 저장
if (_outline != null)
{
// 게임 시작 시 하이라이트는 꺼둡니다.
_outline.enabled = false;
}
else
{
Debug.LogWarning($"{gameObject.name}: QuickOutline 에셋의 Outline 컴포넌트를 찾을 수 없습니다.");
}
}
public override void OnNetworkSpawn()
{
@@ -35,19 +60,45 @@ public class MineableBlock : NetworkBehaviour
private void DestroyBlock()
{
// 1. 모든 클라이언트에게 파괴 이펙트 재생 요청
PlayBreakEffectRpc();
// 2. 서버에서 네트워크 오브젝트 제거 (모든 클라이언트에서 사라짐)
GetComponent<NetworkObject>().Despawn();
}
[Rpc(SendTo.Everyone)]
private void PlayBreakEffectRpc()
// 하이라이트 상태를 설정하는 공개 메서드
public void SetHighlight(bool isOn)
{
if (breakEffectPrefab != null)
if (_outline == null) return;
// 외곽선 컴포넌트 활성화/비활성화
_outline.enabled = isOn;
}
// 서버에서 호출하여 모든 클라이언트에게 흔들림 지시
[ClientRpc]
public void PlayHitEffectClientRpc()
{
if (_shakeCoroutine != null) StopCoroutine(_shakeCoroutine);
_shakeCoroutine = StartCoroutine(ShakeRoutine());
}
private IEnumerator ShakeRoutine()
{
float elapsed = 0.0f;
Debug.Log("흔들림 코루틴 시작"); // 시작 확인
while (elapsed < shakeDuration)
{
Instantiate(breakEffectPrefab, transform.position, Quaternion.identity);
Vector3 randomOffset = Random.insideUnitSphere * shakeMagnitude;
transform.localPosition = _originalPos + randomOffset;
// 좌표가 실제로 바뀌고 있는지 로그 출력
// Debug.Log($"현재 좌표: {transform.localPosition}");
elapsed += Time.deltaTime;
yield return null;
}
transform.localPosition = _originalPos;
Debug.Log("흔들림 코루틴 종료 및 위치 복구");
}
}