39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class EfekPopKenyal : MonoBehaviour
|
|
{
|
|
[Header("Settingan Simpel")]
|
|
public float durasi = 0.3f; // Berapa detik animasinya jalan
|
|
public float kekenyalan = 0.2f; // Semakin besar angkanya, semakin "mentul"
|
|
|
|
void OnEnable() // Pakai OnEnable supaya tiap muncul langsung otomatis gerak
|
|
{
|
|
transform.localScale = Vector3.zero;
|
|
StopAllCoroutines();
|
|
StartCoroutine(ProsesPop());
|
|
}
|
|
|
|
IEnumerator ProsesPop()
|
|
{
|
|
float t = 0;
|
|
|
|
while (t < 1.0f)
|
|
{
|
|
t += Time.deltaTime / durasi;
|
|
|
|
// Rumus matematika simpel untuk efek membal (Overshoot)
|
|
// Dia bakal membesar sedikit melewati 1, lalu balik ke 1
|
|
float s = 1f + (kekenyalan * Mathf.Sin(t * Mathf.PI));
|
|
|
|
// Lerp dari 0 ke ukuran s tadi
|
|
float scaleValue = Mathf.Lerp(0, s, t);
|
|
transform.localScale = new Vector3(scaleValue, scaleValue, scaleValue);
|
|
|
|
yield return null;
|
|
}
|
|
|
|
transform.localScale = Vector3.one;
|
|
}
|
|
|
|
} |