Last active
May 8, 2021 08:47
-
-
Save MattRix/9f71daf75ae6ba2a5fcf1828f849f590 to your computer and use it in GitHub Desktop.
RandomMover - A thing that uses RT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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