Skip to content

Instantly share code, notes, and snippets.

@MattRix
Last active May 8, 2021 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattRix/9f71daf75ae6ba2a5fcf1828f849f590 to your computer and use it in GitHub Desktop.
Save MattRix/9f71daf75ae6ba2a5fcf1828f849f590 to your computer and use it in GitHub Desktop.
RandomMover - A thing that uses RT
using UnityEngine;
using System.Collections;
using System;
using Random = UnityEngine.Random;
public class RandomMover : MonoBehaviour
{
public float distance = 1f;
public float duration = 1f;
public float delay = 0.0f;
IEnumerator routine;
void OnEnable ()
{
if(routine == null) routine = Routine();
StartCoroutine(routine);
}
void OnDisable()
{
StopCoroutine(routine);
}
IEnumerator Routine()
{
while(true)
{
var randomOffset = Random.onUnitSphere * distance;
var pos = transform.position;
yield return RT.Tween(duration,(p)=>transform.position = pos + p* randomOffset, RTEase.ExpoOut,delay);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment