별조각픽업
This commit is contained in:
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user