IEnumerator AIUpdate(float tickSec) { while (true) { GuardController controller = GetComponent <GuardController>(); ChangeMaterial changeMtl = GetComponent <ChangeMaterial>(); if (SearchAroundPlayer() && FarFromSpawnPos() == false) { controller.TrackingMode(player.transform.position); changeMtl.Change(1); } else { controller.PatrolMode(); changeMtl.Change(0); } yield return(new WaitForSeconds(tickSec)); } }