24 lines
717 B
C#
24 lines
717 B
C#
//\$ Copyright 2015-22, Code Respawn Technologies Pvt Ltd - All Rights Reserved \$//\n
|
|
using UnityEngine;
|
|
|
|
public class PickupWobbler : MonoBehaviour {
|
|
public Vector2 wobbleDirection = Vector2.up;
|
|
public float speed = 1;
|
|
public float randomStartAngle; // So they don't all wobble in the same sequence
|
|
|
|
Vector3 originalPosition;
|
|
// Use this for initialization
|
|
void Start () {
|
|
originalPosition = transform.position;
|
|
randomStartAngle = Random.value * 100;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update () {
|
|
var t = Time.time * Mathf.PI + randomStartAngle;
|
|
t *= speed;
|
|
var offset = Mathf.Sin(t) * wobbleDirection;
|
|
transform.position = originalPosition + new Vector3(offset.x, offset.y, 0);
|
|
}
|
|
}
|