Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
Created April 21, 2020 14:17
Show Gist options
  • Save openroomxyz/9046cf004c3a80fee835477f07c20110 to your computer and use it in GitHub Desktop.
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?
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