Created
April 21, 2020 14:17
-
-
Save openroomxyz/9046cf004c3a80fee835477f07c20110 to your computer and use it in GitHub Desktop.
Unity : How to start a Coroutine -s to excute something in same thread and not block it?
This file contains hidden or 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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class EnemyMovement : MonoBehaviour | |
{ | |
[SerializeField] List<Waypoint> path; | |
void Start() | |
{ | |
print("A"); | |
StartCoroutine(FollowPath()); | |
print("B"); | |
} | |
IEnumerator FollowPath() | |
{ | |
print("Start petrol ..."); | |
foreach (Waypoint waypoint in path) | |
{ | |
print("Visiting block : " + waypoint.name); | |
transform.position = waypoint.transform.position; | |
yield return new WaitForSeconds(1f); | |
} | |
print("Ending patrol"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment