Skip to content

Instantly share code, notes, and snippets.

@Manamongods
Last active April 22, 2020 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Manamongods/9c6535b4922b8232a03ed30037d2859d to your computer and use it in GitHub Desktop.
Save Manamongods/9c6535b4922b8232a03ed30037d2859d to your computer and use it in GitHub Desktop.
//Steffen Vetne made this
//Creative Commons 0
using UnityEngine;
[ExecuteInEditMode]
public class Bobber : MonoBehaviour
{
//Fields
public Vector3 localPosition;
public float amount = 1;
public Vector3 localDirection = Vector3.up;
[Header("Time")]
public float startTime;
public float startTimeRandomization;
public float rate = 1;
public float rateRandomization = 0;
private float t;
private float r;
//Lifecycle
private void OnEnable() //Start()
{
t = startTime + (Random.value - 0.5f) * startTimeRandomization;
r = rate + (Random.value - 0.5f) * rateRandomization;
}
private void Update()
{
t += Time.deltaTime * r;
transform.localPosition = localPosition + localDirection * Mathf.Sin(t) * amount;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment