Created
February 18, 2022 11:26
-
-
Save partiallyblind/0d3e08e2bf4d7a36a8491e9428aeab65 to your computer and use it in GitHub Desktop.
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; | |
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