82 lines
1.7 KiB
C#
82 lines
1.7 KiB
C#
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();
|
|
}
|
|
}
|
|
}
|