-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWiggle.cs
More file actions
44 lines (35 loc) · 1001 Bytes
/
Wiggle.cs
File metadata and controls
44 lines (35 loc) · 1001 Bytes
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
33
34
35
36
37
38
39
40
41
42
43
44
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Wiggles a sprite side to side like a stop motion animation.
/// </summary>
public class Wiggle : MonoBehaviour {
public float rotAmnt = 2;
public float frequency = 0.5f;
public float randomAmnt = 0.2f;
private float finalFreq;
private float originalZ;
private float countdown;
// Update is called once per frame
void Start () {
originalZ = transform.localEulerAngles.z;
finalFreq = frequency + Random.Range(-randomAmnt, randomAmnt);
StartOver();
}
void Update()
{
if(countdown > 0)
countdown -= Time.deltaTime;
else
StartOver();
}
void StartOver()
{
rotAmnt *= -1;
var rot = transform.localEulerAngles;
rot.z = originalZ + rotAmnt;
transform.localEulerAngles = rot;
countdown = finalFreq;
}
}