-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFloater.cs
32 lines (26 loc) · 952 Bytes
/
Floater.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using UnityEngine;
using System.Collections;
// Makes objects float up & down while gently spinning.
public class Floater : MonoBehaviour {
// User Inputs
public float degreesPerSecond = 15.0f;
public float amplitude = 0.5f;
public float frequency = 1f;
// Position Storage Variables
Vector3 posOffset = new Vector3 ();
Vector3 tempPos = new Vector3 ();
// Use this for initialization
void Start () {
// Store the starting position & rotation of the object
posOffset = transform.position;
}
// Update is called once per frame
void Update () {
// Spin object around Y-Axis
transform.Rotate(new Vector3(0f, Time.deltaTime * degreesPerSecond, 0f), Space.World);
// Float up/down with a Sin()
tempPos = posOffset;
tempPos.y += Mathf.Sin (Time.fixedTime * Mathf.PI * frequency) * amplitude;
transform.position = tempPos;
}
}