Last active
April 22, 2020 15:51
-
-
Save Manamongods/9c6535b4922b8232a03ed30037d2859d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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