43 lines
1.0 KiB
C#
43 lines
1.0 KiB
C#
using UnityEngine;
|
|
|
|
public class ButterflyTarget : MonoBehaviour
|
|
{
|
|
public float floatAmplitude = 0.5f; // How far up/down it moves
|
|
public float floatFrequency = 1f; // How fast it moves
|
|
public float floatOffset = 0f; // Optional random offset to desync motion
|
|
|
|
private Vector3 startPos;
|
|
|
|
void Start()
|
|
{
|
|
startPos = transform.position;
|
|
floatOffset = Random.Range(0f, 2f * Mathf.PI); // Randomize to avoid synced motion
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
FloatMotion();
|
|
}
|
|
|
|
void FloatMotion()
|
|
{
|
|
Vector3 newPos = startPos;
|
|
newPos.y += Mathf.Sin(Time.time * floatFrequency + floatOffset) * floatAmplitude;
|
|
transform.position = newPos;
|
|
}
|
|
|
|
void OnMouseDown()
|
|
{
|
|
if (ButterflyGameManager.Instance.IsGameActive())
|
|
{
|
|
ButterflyGameManager.Instance.Mole.JumpTo(transform.position, this);
|
|
}
|
|
}
|
|
|
|
public void OnCaught()
|
|
{
|
|
ButterflyGameManager.Instance.RegisterCatch();
|
|
Destroy(gameObject);
|
|
}
|
|
}
|