I have a very simple horror game where there is an enemy. If you get into his radius, he will follow you. But if you aren’t, he doesn’t do anything. I find that boring and was thinking of ways to make him move around randomly. But I couldn’t think of anything. Here is the code that makes the enemy move in the first place:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Walker : MonoBehaviour
{
public float lookRadius = 10f;
NavMeshAgent agent;
Transform target;
void Start()
{
target = PlayerManager.instance.player.transform;
agent = GetComponent<NavMeshAgent>();
}
void Update()
{
float distance = Vector3.Distance(target.position, transform.position);
if(distance <= lookRadius)
{
agent.SetDestination(target.position);
}
}
void OnDrawGizmosSelected()
{
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, lookRadius);
}
}
What do I add so the character moves around randomly?