Files
BABA_YAGA/Assets/TeKniKo_Free/Power_Ups/Scripts/ObjectBounce.cs

37 lines
1.0 KiB
C#
Raw Normal View History

2026-06-03 04:32:58 +07:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectBounce : MonoBehaviour
{
public float bounceSpeed = 8;
public float bounceAmplitude = 0.05f;
public float rotationSpeed = 90;
private float startHeight;
private float timeOffset;
// Start is called before the first frame update
void Start()
{
startHeight = transform.localPosition.y;
timeOffset = Random.value * Mathf.PI * 2;
}
// Update is called once per frame
void Update()
{
//animate
float finalheight = startHeight + Mathf.Sin(Time.time * bounceSpeed + timeOffset) * bounceAmplitude;
var position = transform.localPosition;
position.y = finalheight;
transform.localPosition = position;
//spin
Vector3 rotation = transform.localRotation.eulerAngles;
rotation.y += rotationSpeed * Time.deltaTime;
transform.localRotation = Quaternion.Euler(rotation.x, rotation.y, rotation.z);
}
}