I have a small issue and jus out of ideas how to do it, I want to update a GameObject
Vector3
in realtime but if I use simple Update
method fps drops low and it’s understandable.
Ther is a many objects whit tag enemy in the scene and I want to make a main object to folow the closest and change the object to dolow if another “enemy” object became closer.
I also tryed to use System.Threading
but it did’t give me ane result fps lowers the same way.
Here is small excample of what I’am trying to achive:
Vector3 target;
private void Start()
{
StartCoroutine(UpdatePath());
}
private IEnumerator UpdatePath()
{
target = GameObject.FindGameObjectWithTag("Enemy").transform.position;
StartCoroutine(FolowPath());
yield return null;
}
private IEnumerator FolowPath()
{
while (true)
{
Vector3.MoveTowards(transform.position, target, 20 * Time.deltaTime);
StartCoroutine(UpdatePath());
yield return null;
}
}