Created
February 18, 2022 11:27
-
-
Save partiallyblind/a11edd6ed879d562220e6d6fac5c0702 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 CoroutinesExample : MonoBehaviour | |
{ | |
public float smoothing = 1f; | |
public Transform target; | |
void Start () | |
{ | |
StartCoroutine(MyCoroutine(target)); | |
} | |
IEnumerator MyCoroutine (Transform target) | |
{ | |
while(Vector3.Distance(transform.position, target.position) > 0.05f) | |
{ | |
transform.position = Vector3.Lerp(transform.position, target.position, smoothing * Time.deltaTime); | |
yield return null; | |
} | |
print("Reached the target."); | |
yield return new WaitForSeconds(3f); | |
print("MyCoroutine is now finished."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment