별조각픽업

This commit is contained in:
2026-06-24 20:36:39 +09:00
parent b92bb65ba6
commit 5ff460f9c3
19 changed files with 355 additions and 6 deletions

View File

@@ -0,0 +1,46 @@
using UnityEngine;
public class CollectionManager : MonoBehaviour
{
public static CollectionManager Instance;
[Header("Star Data")]
private int _currentStars = 0;
[Header("CollectionHuds")]
[SerializeField] private StarPieceHud _starPieceHud;
public int GetStarCount => _currentStars;
void Awake()
{
if (Instance != null && Instance != this)
{
Destroy(gameObject);
return;
}
Instance = this;
DontDestroyOnLoad(gameObject);
}
void Start()
{
UpdateUI();
}
public void AddStar(int amount)
{
_currentStars += amount;
UpdateUI();
Debug.Log("Star Added: " + amount + " / Total Star: " + _currentStars);
}
void UpdateUI()
{
if(_starPieceHud != null)
{
_starPieceHud.RefreshUI();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5246c040c89587145b3d5b6f6631a948

View File

@@ -0,0 +1,81 @@
using UnityEngine;
public class StarPickup : MonoBehaviour
{
[SerializeField] private string _playerTag;
[Header("Visual Spin")]
public Transform visualRoot;
public bool rotate = true;
public float rotateSpeed = 180f;
[Tooltip("회전축")]
public Vector3 rotateAxis = Vector3.up;
[Header("Float Motion")]
public bool floatMotion = true;
public float floatHeight = 0.08f;
public float floatSpeed = 2f;
[Header("Sound")]
public AudioClip pickupSound;
private Vector3 startPosition;
void Awake()
{
if (visualRoot == null)
{
visualRoot = transform;
}
}
void Start()
{
startPosition = transform.position;
}
void Update()
{
if (rotate && visualRoot != null)
{
visualRoot.Rotate(rotateAxis.normalized, rotateSpeed * Time.deltaTime, Space.Self);
}
if (floatMotion)
{
float yOffset = Mathf.Sin(Time.time * floatSpeed) * floatHeight;
transform.position = startPosition + new Vector3(0f, yOffset, 0f);
}
}
public void CollectStar()
{
Debug.Log("CollectStar called.");
if (CollectionManager.Instance != null)
{
CollectionManager.Instance.AddStar(1);
}
else
{
Debug.LogWarning("CollectionManager not found.");
}
if (pickupSound != null && pickupSound != null)
{
SoundManager.Instance.PlaySFX(pickupSound);
}
Destroy(gameObject);
}
public void OnTriggerEnter(Collider other)
{
if(other.CompareTag(_playerTag))
{
CollectStar();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 400203bf2ecfc114f91e0dc63fe1e219

View File

@@ -0,0 +1,31 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class StarPieceHud : MonoBehaviour
{
[SerializeField] private Image[] _imageArray;
[SerializeField] private TMP_Text _countText;
[SerializeField] private GameObject _StarPieceUIRoot;
public int GetStarCount => CollectionManager.Instance.GetStarCount;
public void RefreshUI()
{
_countText.text = $"{GetStarCount} / {_imageArray.Length}";
for(int i = 0; i<_imageArray.Length; i++)
{
if(i < GetStarCount)
{
_imageArray[i].gameObject.SetActive(true);
}
}
}
public void StarPieceHudToggle()
{
_StarPieceUIRoot.SetActive(!_StarPieceUIRoot.activeSelf);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1b4836d7a85fcc848b5a25b8a2e51a36