Skip to content

Instantly share code, notes, and snippets.

@partiallyblind
Created February 18, 2022 11:26
Show Gist options
  • Save partiallyblind/0d3e08e2bf4d7a36a8491e9428aeab65 to your computer and use it in GitHub Desktop.
Save partiallyblind/0d3e08e2bf4d7a36a8491e9428aeab65 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class PropertiesAndCoroutines : MonoBehaviour
{
public float smoothing = 7f;
public Vector3 Target
{
get { return target; }
set
{
target = value;
StopCoroutine("Movement");
StartCoroutine("Movement", target);
}
}
private Vector3 target;
IEnumerator Movement (Vector3 target)
{
while(Vector3.Distance(transform.position, target) > 0.05f)
{
transform.position = Vector3.Lerp(transform.position, target, smoothing * Time.deltaTime);
yield return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment