Created
August 1, 2016 23:11
-
-
Save trentrand/1c06d177b95a4678b38aa0d740521349 to your computer and use it in GitHub Desktop.
This file contains 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
using UnityEngine; | |
using System.Collections; | |
public class BubbleBobber : MonoBehaviour { | |
private float timer = 0.0f; | |
float bobbingSpeed = 0.18f; | |
float bobbingAmount = 0.2f; | |
float midpoint = 2.0f; | |
void Update () { | |
float waveslice = 0.0f; | |
Vector3 cSharpConversion = transform.localPosition; | |
waveslice = Mathf.Sin(timer); | |
timer = timer + bobbingSpeed; | |
if (timer > Mathf.PI * 2) { | |
timer = timer - (Mathf.PI * 2); | |
} | |
if (waveslice != 0) { | |
float translateChange = waveslice * bobbingAmount; | |
float totalAxes = Mathf.Abs(horizontal) + Mathf.Abs(vertical); | |
totalAxes = Mathf.Clamp (totalAxes, 0.0f, 1.0f); | |
translateChange = totalAxes * translateChange; | |
cSharpConversion.y = midpoint + translateChange; | |
} | |
else { | |
cSharpConversion.y = midpoint; | |
} | |
transform.localPosition = cSharpConversion; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment