Skip to content

Instantly share code, notes, and snippets.

@MugOfPaul
Created May 7, 2020 15:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MugOfPaul/55dd7a4f90b9fdf1be9cfb2d71922d03 to your computer and use it in GitHub Desktop.
Save MugOfPaul/55dd7a4f90b9fdf1be9cfb2d71922d03 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class FloatySpinny : MonoBehaviour
{
public bool m_Spin = true;
public Vector3 m_SpinAxis = Vector3.up;
public float m_SpinSpeed = 1.0f;
public bool m_Float = false;
public Vector3 m_FloatAxis = Vector3.up;
public float m_FloatSpeed = 0.25f;
public float m_FloatDistance = 0.1f;
private Vector3 m_OriginalPos;
void Start()
{
// cache the original position
m_OriginalPos = transform.transform.localPosition;
}
void Update()
{
if (m_Spin)
{
// advance the rotation
transform.rotation = transform.rotation * Quaternion.Euler(m_SpinAxis * (Time.deltaTime * m_SpinSpeed));
}
if (m_Float)
{
// advance the "floaty"
transform.localPosition = m_OriginalPos + (m_FloatAxis * (m_FloatDistance * (Mathf.Sin(Time.time * m_FloatSpeed))));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment