How to make AI wonder about? C#?

Hi There!

So, I was wondering how to make a (for example) Monster wonder around until it saw a player. Then Start walking towards you. I have the walk towards part, but I dont know how to make them just walk around!

If you could help that would be great!

Thanks

-Sir

Game Development @ Tuts+ has more than you’d ever want to know about wandering:

it is really easy to do so;-
1- make a cube and remove the mesh render component, now create your monster and give it nav mesh agent component, finally create a c# script and set the monster destination to your cube.

code:-

         using UnityEnigne.AI; 

         public NavMeshAjent myAjent; //your monster, make sure it has nav mesh ajent
         public Transform Ajent_Destination;// your cube
         public Transform temp_playerDestination;// you i mean the player

         private bool isChasing_PLayer = false; 

         void Update()
         { 
            myAjent.SetDestination(Ajent_Destination.position);
           if(isChasing_Player == true)
             {
                   myAjent.SetDestination(temp_playerDestination.position);
              }
            else
             {
                 myAjent.SetDestination(Ajent_Destination.position);
              }
          }

        void OnColliisonEnter(Collider other)
        {
              isChasing_Player = true;
         }

Now we only need to teleport the cube , make sure it has box collider with is trigger set to true make another c# script name it as Collide and ,

code:-

       public int min_X = 0;
       public int max_X = 0;

       public int min_Z = 0;
       public int max_Z = 0;

        void OnColliisonEnter(Collider other)
        {
            this.gameObject.transform.position = New Vector3(Random.Range(min_X , max_X) , 0 /*you can modify this thing by creating min,max variables for Y*/ ,Random.Range(min_Z , min_Z ));
         }

And you are good to go, hope this works I haven’t tested this script in unity so please just check for spelling cause this surely goanna work , leave the comments for any suggestion or query well this is my first ever unity solution and I am programming for a month now!!!