Hey guys this script worked perfectly last time I ran it but now it suddenly stopped working. I havent changed anything, is there an update that has deprecated some of this and can someone help me rework it if so?
I have 6 trees as a possible location which i assign in the editor
[SerializeField]
private float _speed = 32f;
private float _closeThreshold = .1f;
[SerializeField]
private Transform _treeTopLocations;
//The position we want to move to
private Vector3 _targetPos;
void Start()
{
//Set our first target location to where we already are
_targetPos = transform.position;
StartCoroutine(MonkeyMovement());
}
void Update()
{
//If we aren't close to our target location
if (Vector3.Distance(transform.position, _targetPos) > _closeThreshold)
{
//Find the direction from where we are to where we want to be
//Normalize it to get a direction rather than the whole distance
Vector3 _currentDir = (_targetPos - transform.position).normalized;
//Move towards the target
transform.Translate(_currentDir * _speed * Time.deltaTime);
}
}
IEnumerator MonkeyMovement()
{
while (GameManager.gameManager.gameOver == false)
{
if (UIManager.uIManager.pauseMenuVisible == true)
{
yield return null;
}
else
{
//Dont get a new target for 2 seconds
yield return new WaitForSeconds(1);
//Get a new target
Transform newTree = TreeTopLocations();
_targetPos = newTree.position;
}
}
}