2019-08-07 21:25:39 +02:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class Bobbing : MonoBehaviour {
|
|
|
|
|
|
|
|
|
|
public Transform BobbedTransform;
|
|
|
|
|
|
2019-08-07 21:40:16 +02:00
|
|
|
|
[Range(0, 1)]
|
|
|
|
|
public float BobbingMultiplier = 1;
|
2019-08-07 21:25:39 +02:00
|
|
|
|
public float BobbingGravity = 0.5f;
|
|
|
|
|
public float BobbingLaunchSpeed = 5f;
|
|
|
|
|
public Vector2 BobbingDirection = new Vector2(0, 1);
|
|
|
|
|
|
|
|
|
|
private float BobbingSpeed;
|
|
|
|
|
|
|
|
|
|
private float CurrentBobbingState = 0;
|
|
|
|
|
|
|
|
|
|
void Update() {
|
2019-08-07 21:40:16 +02:00
|
|
|
|
BobbingSpeed -= (BobbingGravity / 10 * Time.deltaTime);
|
2019-08-07 21:25:39 +02:00
|
|
|
|
if (CurrentBobbingState <= 0) {
|
2019-08-07 21:40:16 +02:00
|
|
|
|
BobbingSpeed = (BobbingLaunchSpeed / 10);
|
2019-08-07 21:25:39 +02:00
|
|
|
|
}
|
|
|
|
|
CurrentBobbingState += BobbingSpeed;
|
|
|
|
|
|
2019-08-07 21:40:16 +02:00
|
|
|
|
BobbedTransform.localPosition = BobbingDirection * CurrentBobbingState * BobbingMultiplier;
|
2019-08-07 21:25:39 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|