Welcome back to the second part of creating this world mentioned really spelling challenge.
Now what we're up to is trying to sort out that very big array of all the children objects and trackable
to find just the ones with the markers on it.
Now if I again Pressplay and we have another little bit of a look at what we get in the Hauraki case
of them they and Pooles that and trackable you can see that immediately under trackable of just the
mock or objects anything that is on Nye's Marcus or any of the augmented objects in this case that takes
the children of those.
So we can filter at least that we've got.
But just picking up the immediate children of trackable and nothing else.
And then we will know in this case that that's the only things that we've picked up into our right.
So let's go back into the code.
And what I'm going to do is just change this for loop here and above it add in a new list.
The reason being is that first of all I'm getting everything that is transform and trackable including
trackable itself.
The least is going to hold all of the marker objects and therefore I've created a list of transforms
called markers and then said new list to initialize it inside of the Fulop that we have before.
We're now going to test each transform that we put in this old transforms and if its parent game object
is equal to trackable then it must be an immediate child of trackable.
It can't be trackable itself and it can't be any of those ticks because their childhood to the Marcuse
themselves.
So if that is the case then we add the transform to Mochis So at this point after this fall we've got
a list of markers which are just the images I see day whatever ones that you've picked up now that the
Marcuse in this list we can use the link library to order the least after the full loop.
We'll add some more code to order the list and then print out what's in it in order.
So here we go.
Markus equals Marcuse dot orda by descending.
And we're going to order h Mocca in that by the exposition and make it into a list to return back into
Marcuse So this will update whatever the order is there in order of the x position in descending order.
Remember that the more positive the x value then the more to the left that Leisha is.
So therefore we need to do it backwards instead.
Then I've got a full loop and I'm doing a full life with a counter rather than a 4 h.
You could of course use a for each to just print this out but I'm doing it this way for a specific purpose
that we'll see in a moment.
And then inside of it we're printing out just the name of whatever that marker is.
So let's now say that and go back to unity and run it again.
Let me clear the console.
And we go looking for OWL
letters.
There we go.
So we've got them and you can see either in your console or mock console that we now have these values
ordered.
So it says see I ah we now have it in that order.
And if we were to put it in the reverse order which we can actually do.
So let's try that out.
So I'm just going to swap these letters around then try and pick them up again.
Then have a look at what we've got over in the console we've got.
I see ah.
And that's what it says here.
I see.
Ah Next we need to come Peja what is printing out in sort of that loop which is the order of an Machias
with a particular set.
Words are back in the script.
Let's go up to the top of that code and I'm going to create a public string and we'll call it word and
set it to the word they're trying to spell.
So not word ka.
In this case.
Right.
So there is a string.
Word is a variable that we need to check against the order of the markers in the order of the markers
is being printed out in this for loop.
So can you now have a bit of a think about how we are going to compare each marker in turn with each
Litta that is in Al would pause the video now.
And when we come back I'll show you how I do it.
Now within the code were already looping through the markers down here in the order in which they've
been reading from left to right.
So why don't we take advantage of this so at the same time we're looping through the markers we can
loop through our word.
If the marker position is the same character position or in the word then it's a match.
Now we need to count these matches so I'm going to create an interest up he called Count correct and
initialize it to zero or then what I'm going to do is on to here and at this point you could take out
that actually just comment that it was not in the road.
We can put in an IF statement to check if the market is the same character as the word I and that statement
will click this.
So if Mark is at position by we need to get the game object we need to get the game object's name.
Remember we've got those transforms that are children of the trackable which have that funny name like
their I under school 1 or whatever.
So we're going to just ask if it starts with the name.
In this case the same character that scene would aw.
Now starts with requires that you give it a string value.
If you get word all.
You're actually only getting a character and therefore starts with like you very much but a really easy
way to convert a character into a string is to add something to the end of it.
And in this case we actually also want to check that the name of the Mokka starts with the word character
plus and underscore.
So if it's I underscore then it's equivalent of the eye.
That is in a word because you might have some other child thing which you shouldn't have but that might
come up with a different sort of name which might start with eyes.
It was like Apple I don't know why but if it was apple it would still match the eye with the eye.
But we want to make sure we've got this underscore in there just to make sure.
OK so in here if that is correct then can't correct.
Plus plus now after these for loop has executed fully if the can't current value is equal to the length
of your word then you know that you have a matching woods and he will get.
If count correct equals word length then
debug log correct.
Like that and maybe you can just put an else in here.
If it's not it's obviously wrong.
And so we will just put a de-bug up log.
Roll.
So we can just see that in action.
All right so save that let's go back and now try this out.
So press play.
Now remember we've got the word programmed in as Caue.
So let's have a look at what's still got my old car to set up from before and it's printing out wrong
wrong wrong remember.
H time it finds a single Mokka is going to run that on image recognized.
OK.
So that's why I wrote it three times it now.
Let's just modify this around.
And now we have a current that's popped up in the console
now as it stands every single trackable object or marker that is found.
Ends up with a tick on it because that's the drawable object.
We want to control that.
If the marker is correct.
So it's in the correct position the right letter.
We want to take on it.
Otherwise we went across to a PIA.
So we're going to get rid of this drawable and control that instead through our code.
So let me just set that drawable to none.
Then we'll go back into our code at the very top.
We want to Maum Publix.
So we have a public game object and we will call it a tick and a public game object and call it a cross.
Then what we're going to do is instantiate these on the Mokka.
If the letter is correct or not so we can do that down here.
So go down into our code where we're actually doing the checking and after we've counted correct we'll
add this and this will then instantiate a take on that particular Mokka so that Machias position and
rotation and it will also make the object itself the Teac a child of the Mokka by setting its parent
property to the Machias transform.
Now we have to do this also for our cross so we do in Elsin heah and in sort of else we'll have exactly
the same thing as ziss but instead of take it's going to be cross so we went across object wound across
prefab and a cross object there.
All right.
So we saved that go back to unity and go over to your spelling control long and there should be two
positions available.
Take an crossway you can drag and drop those missions.
Prefabs whatever they are into this tick tick and cross full cross.
And now we can check that out.
So we press play and we go find a word OK.
So we've got an X appear on eye with a tick as well.
So what's going on here.
Well remember when the we could circles around to try and find the markers in a single frame it doesn't
necessarily pick them all up at the same time.
And so it might have just recognized I bought self without the other two.
And so it tried to compare I with the word cow which is obviously wrong.
So it said no that's wrong.
And given it cross and then life on when it picked up all three and compared them with carts it all
yes these are all right but that doesn't help I.
That still has that cross on it.
So really what we should do is ONLY be checking if we have the correct spelling when we have the correct
number of markers.
OK so let's just go back into the code quickly and add a single line.
Now we should do this before we start doing lots of processing but we need to know how many markers
we've got so let's do that just before we go and order them.
If Marcuse don't count does not equal the word length then we just do return.
So we don't bother with the rest.
And that's it.
So save it and we'll try that again.
So back into play we'll now go over and try and find out column OK.
Oh good.
Now if I lose those markers and try and pick up this D.
So only seeing one marker you can see in the hierarchy that that d one has a P it because it's found
it.
But it's not enough letters to try and do a word check so therefore it just completely ignores it.
Right so what happens when we spell Khal wrong.
So let's have a go.
OK so now you can say that it's told us which ones are correct in the correct spot for spelling the
word count.
But the day is completely wrong.
OK.
And we've also got the ability to now print out with.
It is correct or not.
So we'll come back in the next video and actually add in like a character to do a little celebration
if the spelling is correct.