So far, we've got one agent that can put together a string of actions to satisfy a single goal, and
we can tell what's going on with those goals.
If we look in the console at the moment, which gives us a little bit of an idea of the plans for the
agent.
In addition to this, I've created an attaches as a resource to this video Agent Visualizer.
So if you download that.
Zip, unzip it and then just drag and drop that folder into your assets.
Hold on.
First of all, we should stop pausing and playing drag and drop that in.
So it's the agent visualizer here.
Now, the Agent Visualizer has two scripts in it has one script, which is the agent visual that you
can attach to any of your agents.
And then there's a G agent editor that needs to go into a folder that's called editor.
So go back to your assets and just create a new folder, call that editor and then open that up and
grab that G agent editor and drag and drop that into editor.
Looks like I already had editor in there.
So that one's now empty.
I'll just delete that.
Okay.
So now that we've got that, you can grab your G agent visual and if you click on your patient drag
and drop that into the inspector.
And then we're going to just make sure that we put these changes back to our prefab.
So go up to the top of the inspector and where you've got overrides, just click on that and there's
an apply all button next to it and that'll make sure that all of the patients that get spawn from your
prefabs have the same things on them.
Now this G agent visual actually uses inspector editor code, which I'm not going to go through in this
course.
But if you're interested, I guess you can have a dig around in the code.
Now, if we press play, you'll see that and then pause it that this agent visual actually shows you
what the current action is, what the goals are that the agent is trying to satisfy, and the actions
that it has now.
It's not currently printing out the plan, but there's no reason why you couldn't do that.
And if you have a look at the script, then it will give you a pretty decent idea of how you grab the
data from your agent and actually put it into this little area.
But I just created this to help me to make sure that I can see everything and that we can also see very
quickly the pre conditions and the effects and to make sure that things are spelt correctly and that
things are going to all line up when we start to press play.
Now it's time to program the nurse and this is where things start to get interesting.
The nurse can't go into action to get a patient until there's a patient waiting.
So first of all, let's create our nurse script just like we have our patient script, and then we'll
work on it from there.
So let's just grab the patient script and control D to make a copy of it.
Then we will call it nurse and open it up.
Change it from patient to nurse.
So the nurse is going to run the base start, as did the patient.
But the goal in this case will be not is waiting, but treat patient.
And then we add the goal.
So we'll just leave one goal in there at the moment.
So save that.
Let's go back into unity and we will attach that to our solo nurse that we currently have.
So grab that and put it onto the nurse.
Now the nurse's action to get patient will be the first one that we write.
So let's just grab hold of one of the patient ones, like go to hospital and copy it.
Control.
DX And I'm going to call it Get Patient.
Then open that up and rename the class.
To get.
Patient.
And then we'll save it.
Go back to Unity and attach that to our nurse.
So get patient is just there.
Now the action name will be get patient so we can name that there get patient.
And our after effects for now will be.
The goal that we just added.
So we're going to add one and we will call it Treat.
Patient is going to be our after effect.
Okay, now we need a precondition.
So what is the precondition that we're going to set?
Well.
The nurse hasn't done anything to trigger this.
We actually need the world to trigger it or we need something to change in the world that's going to
trigger it.
So in these pre-conditions, what I'm going to do in here is just add one, and the precondition in
this case is going to be waiting or patient waiting.
So we've got this waiting.
Where is waiting going to come from?
So who's goal or who state is that going to be?
It's going to be the world's state and it has to be triggered by the patient when the patient starts
waiting.
So what we need to do is go into our patients waiting code and in the post perform.
What we're going to do here is add in a world state.
So g world.
Dot instance, dot get world.
Dot modify.
State waiting.
One.
So it's going to add one patient that will be waiting.
So now that the patient is going to inject this waiting state into the world, we're going to go back
and start monitoring it.
And that's where this canvas item that's been disabled sitting here causing you a few warnings throughout
comes into play.
So just turn that canvas back on.
You'll see that there's a text box called World Status.
And this is just to display what the world states are and purely just for you to see.
And then when you're not using it anymore, you can just turn it off.
But we need to update the world states to what's in the Dictionary of World States.
And that means writing this script that's missing down the bottom.
So let's go and right click in here and we'll create a new script called Update World.
I open that up and it's going to be very short.
First thing it's going to do is be given the text.
So public text states.
And then in the late update, we'll do this because we don't want to do it very often.
Get rid of the start.
And then we want a dictionary which is of course our string int and world states.
Equals G world dot instance, dot get world dot get states.
Now you could just use this directly in the next for each statement that we're going to create, but
I've just done it there to make the code just a little bit shorter and then we'll just put states dot
text.
Equals empty.
Just get rid of that text.
And then down in here, we want for each key value pair, which will be a string and an int s in world
states.
And then we will just put states dot text plus equals s key.
So that's our string plus a comma space plus a value in case you're actually using that value.
And because we're modifying it, it will update as we're adding patients.
So it's going to go waiting one waiting to waiting through and actually tell you how many are waiting
and.
And put a new line in there now in order to access this text that doesn't seem to like.
Don't forget right at the top we're going to need using unity engine dot UI in order to pick that text
up and those errors should then go away.
If we redefine that as a text.
Okay, good.
So save that.
Let's go back into unity.
And what we're going to do is click on our world states, object in the hierarchy and just put that
missing script back into where it was.
And the text component, which is up here, you can just drag and drop that down into the states case.
So it's this one that's on the same object into states.
And now when we run it, we're going to see that when our patient comes in and goes to the waiting room,
then we will get waiting, appearing up here with a number.
So let's just wait till one of these guys gets in there.
Okay.
Here we go.
He's in there he is now.
Waiting and waiting is one, two.
And as they bunch up and remember, they actually do have to hit the right spot in order to be classified
as waiting.
But it is eventually growing.
So now it's this particular state here that we want to affect the nurse and inject back into the nurses,
get patient action.
Now, that is, in fact, happening.
But why is the nurse moving?
Well, we haven't set the nurses target.
The target needs to be the patient that the nurse needs to pick up.
But just to test that the nurse is actually running this get patient.
Let's just for now give the target to the nurse of that waiting area so she'll be moving towards there.
But it's not the right way to go because we want her to find her actual patient.
So let's just test this again and we'll press play now while we're waiting for these guys to come in.
I hope I'm not being too gender biased or sexist or whatever you might call it by calling the nurse
a she and the patient are he, but to me they kind of look like that, so I'm just going to go with
it.
Okay, so here we go.
Here comes our patient.
He's in there, should trigger the nurse.
And there goes the nurse into action, running that particular get patient.
Now, she's not going to do anything else because that's it.
That was the only thing she knows how to do.
But she's only going into that waiting area, not getting the patient.
And so we'll add that functionality when we come back in the next lecture.