// Jimmy Vegas Unity Tutorials // This script willl make your NPC walk using System.Collections; using System.Collections.Generic; using UnityEngine; public class NPCAI : MonoBehaviour { public int xPos; public int zPos; public GameObject theDestination; public int positionNumber = 1; void Start () { xPos = 18; zPos = 94; theDestination.transform.position = new Vector3(xPos, 1.794543f, zPos); positionNumber += 1; StartCoroutine(NextLocation()); } void Update () { transform.LookAt(theDestination.transform); transform.position = Vector3.MoveTowards(transform.position, theDestination.transform.position, 0.05f); } IEnumerator NextLocation() { if (positionNumber == 1) { yield return new WaitForSeconds(11); xPos = 18; zPos = 94; theDestination.transform.position = new Vector3(xPos, 1.794543f, zPos); positionNumber += 1; } if (positionNumber == 2) { yield return new WaitForSeconds(9); xPos = 2; zPos = 94; theDestination.transform.position = new Vector3(xPos, 1.794543f, zPos); positionNumber += 1; } if (positionNumber == 3) { yield return new WaitForSeconds(10); xPos = 2; zPos = 76; theDestination.transform.position = new Vector3(xPos, 1.794543f, zPos); positionNumber += 1; } if (positionNumber == 4) { yield return new WaitForSeconds(8); xPos = 18; zPos = 76; theDestination.transform.position = new Vector3(xPos, 1.794543f, zPos); positionNumber += 1; StartCoroutine(NextLocation()); } } }