MIF_E31230837/Assets/Script/EarthAnimation.cs

33 lines
795 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EarthAnimation : MonoBehaviour
{
[Header("Float")]
public float floatSpeed = 1.2f;
public float floatHeight = 15f;
[Header("Sway Kiri Kanan")]
public float swaySpeed = 1.2f;
public float swayAmount = 8f;
private Vector3 startPos;
void Start()
{
startPos = transform.localPosition;
}
void Update()
{
// Float naik turun
float y = startPos.y + Mathf.Sin(Time.time * floatSpeed) * floatHeight;
// Sway kiri kanan (sedikit offset biar tidak serentak dengan float)
float x = startPos.x + Mathf.Sin(Time.time * swaySpeed + 1f) * swayAmount;
transform.localPosition = new Vector3(x, y, startPos.z);
}
}