별조각픽업
This commit is contained in:
46
Assets/02_Scripts/Managers/CollectionManager.cs
Normal file
46
Assets/02_Scripts/Managers/CollectionManager.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Managers/CollectionManager.cs.meta
Normal file
2
Assets/02_Scripts/Managers/CollectionManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5246c040c89587145b3d5b6f6631a948
|
||||
81
Assets/02_Scripts/Managers/StarPickup.cs
Normal file
81
Assets/02_Scripts/Managers/StarPickup.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Managers/StarPickup.cs.meta
Normal file
2
Assets/02_Scripts/Managers/StarPickup.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 400203bf2ecfc114f91e0dc63fe1e219
|
||||
Reference in New Issue
Block a user