In this lecture we're going to look at how you can have multiple markers detected within the one scene
so that you can say two things at once.
So far we've only had a single mark.
Now if you have a look at your image tracker in the inspector you'll see a field called the concurrent
targets which is by default set to 1.
If you've tried to put more than one car in your scene at once then you'll know it doesn't work with
this current thing unless you change these concurrent targets.
So if you set it to let's say three we can pick up all those different cars we can then run that and
have more than one on the screen.
So let's just try that out.
OK.
So if we move the camera at where it can see two markers at once.
We've now got a family car and sports car showing up all right.
So what are we going to do in this lecture is not just show up to cars but we're going to add two more
markers to this.
I read one and you can see the images I've already got my project.
And a blue one.
Now these images are attached to this lecture as a or so just bring them in and add them into your assets.
They are going to allow us to change the color of the car that is being displayed on the markers.
Now to add these two images to asset of Marcuse I'm not going to use that we could choose studio.
So instead I'm going to use something that has been built into unity with the chewed plug.
If you go up to a window in the main menu go down you'll see a WTC Editor click on that and it will
bring up a list of all of your strange assets.
We could choose.
And you can click on the one that you're working with in this case it's the car magazine that we created
previously.
Inside there you will see all of your markers.
So yes this has existed the whole time you've been going to the Web site to create these.
But that's good because that's the first way to create because this is another way to correct markets.
But when we get on to 3-D objects in that we will have to go back to the Web site because there's no
editor currently available inside.
Unity is also good for you to get familiar with all the different tools that are on that Web site because
it's more extensive than what you've got in this editor.
But for us we're just adding two more images to here so we can do is click on your WTC file you want
to put these two images into and then click on the Add button.
I'm going to add the blue.
So just double click on that.
Now it's a little bit sensitive work keeps disappearing coming back.
Let's just go add and add the red one in.
So it does.
It's not the ideal editor does have a few little quirky things that it does but it is pretty usable
once you've got those in there.
Click on apply and then if you select the Mokka it's going to tell you how many stars in this case I've
got three on this blue and the red has got two Ok so it could be a little bit better.
But I know it does work because I have used it previously.
So we will just go with this though it is really a good idea to try and get those three stars and if
you look on all of these other ones we put in previously they were three stars.
Now while testing this we have encountered a few issues with these WTC editor might not work.
It might not be able to find the MoCCA and you might find that they disappear when you hit play as well.
If that happens then just use the web saw the wicked two studio method of creating these WTC files.
The other thing I've also found is that this editor doesn't seem to train as well as the online one.
So this red marker in this case has two stars.
But when I put it through the on loan we could choose studio.
I get three stars instead.
So I'd say that the Web site is your best bet.
Even though the WTC editor inside unity is convenient if it does work for you.
Write So you've added those won't disappear again.
And I'll just close that window down.
Click on your image tracker.
We're going to now change the concurrent targets to five.
And if you click on your sports car or family car should say then have a look in your target list you'll
see that you've got the blue and the red now showing up.
Make sure that they're not tweaked on anything because you only want these to be the particular cars.
Now add the blue and red as separate objects so to do that are just going to grab the truck and duplicate
it twice with controlled day all night.
The first one read and then I'll make the next one blue.
Now on the red one we're going to come over and turn on the red mark after that and we'll turn off the
truck that it was before.
For blue we will turn on blue and again turn off that truck marker so that these two objects are only
recognizing their images.
In addition below we don't want it to have a drawable truck.
So let's just set that to a non and the red.
We don't want that to pop up a truck either.
So we'll set that to none.
So if these things are set to none.
And you've got no way of running any code up here.
And how do they then with their magic and change the color of the car.
Well what we're going to do is work with days events that we could plug in comes with.
And it allows us to overwrite an on image recognized method and an on image last method.
So we'll make our image recognized turn the car that is on the screen to the color of Amaka add on image
lost when that market goes away will turn the car color back to white.
Now you also might have just noticed if you have a cane.
Is it my car.
Now why.
Because I was playing Ratha material before.
There were originally a gray silvery color.
So that's just something I've done.
All right so let's now write some code in the assets folder.
I'm going to create a new C-Sharp file which you can see is already they have called Color control law.
And let's go into that and edit it.
So what you're going to need yours to look is at the top we have unity engine system collections generic
and using it.
This is the important one to make sure that you've added as one of your import libraries.
Now the Clauss itself does extend from one to the hive.
So it's called Kaala control and I'm overawing to function.
So we've got an on image recognized which is passed the image target.
And with that we're just printing out its name.
Now this don't name with the capital N is belongs to the image top it's not a name that you get with
your game object.
So it's going to be possibly different to what you've named your object and I'll show you that in a
moment.
So we're printing out the target name when you found it and we are also printing out the target name
when you've lost it.
And the last is on image last.
Right so this target name here.
If I just go down into unity I'm going to click on the red image this red it's game object name is red
with a capital.
Ah.
OK so that's the unity game.
Object Name with a small in the wicked Eudes target dot name is.
This one here.
So it's the name that you would have given to the JPEG file.
And in our case it's red with a lower case.
Ah.
So we want to basically see this red and if we need to figure out which target we've picked up in our
code we'll also be testing for red with a lower case.
So make sure that you've saved that code which was just here again.
Color control go back into unity.
We're going to add in the hierarchy right click Create an empty and let's call that our color control
the and two that will drag and drop that color control a script like that.
Now that makes it available for the red and blue items to grab hold of the own image recognized.
So click on the red then over in the Inspectah under a vent so we're going to click on Add an on image
recognized drag and drop your color control into that field there.
And then for the function if you drop that down and let me just make this a bit narrower.
We can go to color control and then we find on image recognized and add it in there.
So that's going to get run when the read image is recognized.
Now you do the same thing for last.
We will take plus drag and drop color controller into there and then find that function on image lost
like that.
Now I need to do exactly the same thing for the blue.
So just quickly add these things recognized color control or again is lost.
All right so now we're ready to try this out just before we do select your Emmys truck and make sure
that your concurrent targets are set to 5s.
It's going to pick up everything for you.
Right.
So let's press play.
And first of all we need to find Khaw actually probably done because they got this color functionality
and yet all were doing is seeing if the de-bug is going to show up when Al red marker shows up.
Now this red marker is not the best.
Remember it's only 2.
You can see in my hierarchy that it has found that red mark up because it has become active and I do
have a target found read that got written down in my console.
So if I just get rid of that it will turn off in the hierarchy.
And I've also got tagged last is read written down in the console as well.
So if I bring it back again it's it.
So it's not too bad.
One of the biggest issues with Machias can be glare and you can see on the edges of my Makara eventually
got sticky tape around there and it can make it much harder for it to recognize.
You know it's not too bad.
Could be a little bit better.
But it is finding it.
Now I want to modify our script so that when we find the target image depending on which one it is we
will change the color of the car to a blue or red.
So come back into color control in the own image recognized just above and de-bug law and I'll just
leave that in for debugging purposes.
Let's add this bit of code scroll up for you so you can see the whole thing.
So this is now inside of on image recognized.
What I'm doing is creating a variable the top called pint Cola and it's going to be the sort of the
default color and it's set to what so you can see where my car having become what has come from then
I've got some if else statements that check what the target that's coming through into this method's
name is Taggert nine.
If it's equal to read case of the lower case ready because it's the name of your JPEG file then Alpina
color will sit to read if the target name is blue then we'll sit Alpina color to blue.
OK so that's fairly straightforward.
The next bit's a little bit more difficult because what you've got to do is find the cars that exist
in the hierarchy so they're the cars that have been instantiated and are now in view of augmented experience
and then on their Michigander find their material and then change the material color.
So was a little bit of digging around.
First of all I'm going to tag all of the cars with the tag Khaw so that we can just search through the
hierarchy with find game objects with tag and pick up all the cars that currently exist in the scene.
Now we can then loop through those and change their color and I've added little de-bug lawn and he also
tells us how many cars we found if any at all.
I've then got a 4 h which is going to loop through all of those cars that are in the scene.
Usually it's going to be just one and then four h CACI in this case we're going to find the mesh render
up that is attached to it some way in its children.
So it's See get component in children for the Mischer Indra will sign that to something called AMA Mischer
enduro.
And then we will use the mesh renderers shared materials array which is an array of materials loops.
Each one of those and change the color to the paint color.
So this is a loop through all the materials.
This is sitting the color of the paint color.
Now where are all these bits and pieces in a sane way that they Let's just say it before we go back
into unity and we'll go back into unity.
The first place to look is in our prefabs of the vehicles and where we found these vehicles.
So the family called the sports car and the truck.
If you click on the family car you know it's a prefab and if you look over the inspector you can say
it's got a rigid body and it's drive code and everything on it.
Now that's not the bit you have.
Look there's no Romish render on there.
So that's not where the materials are.
If we roll out and have a look inside of this object you'll see that there's a family car chassis and
each one of those vehicles has the same kind of set up the cestus object itself has the mesh renderer
attached he's the best render out that we're trying to get their code and then it has materials.
And if we just look down you can see that it has a whole bunch of material so that loop that's looping
through the materials is going to set all of these materials to that red or blue color.
So it's indiscriminate of which one and you'll see the entire CA turn red or blue if you want it to
be a little bit more picky.
You could then test for the name of the material before you change it so maybe you only want to change
the car paint to bay red.
You don't want the gloss and the and so on in the lot and all of that to go red as well.
For now we're just going to sit them all.
Now this code has to be transferable to all of you augmented objects all of your cars so they need to
have the same kind of structure and because all of these cars were created essentially by the same artist.
They're all existing in the same package.
Then they set up their hierarchies all the same.
We click on the sports car.
Roll that out.
Sports car has a chessy.
Select that and then you'll see it's got a mesh renderer and that Mischer Indra has the same materials.
It also has a car paint material there.
If you want to just target that so the name of that is the same the name of that will be the same on
the truck as well which makes that code work on all these different objects even though they have a
different mesh.
They're still sharing the same load of materials which makes it really convenient.
All right so that's where all of those things are.
Before we continue we do have to select all of prefabs of our vehicles and give them the tag Caue.
So you'll want to select first of all the family car come over to the inspector.
Add in the tags add a tag call it car.
Then come back and add that car tag to the family car.
Click on your sports car and car and the truck ad ka OK let's test this out press play then you want
to find your CA first because that needs to be in the scene.
In order for it to change the color.
So to put that out there and let's try the red
and then we'll try the blue
been having trouble with this blue mark and I really do think it's the sticky type.
There we go.
OK.
So now we've got both of those working.
What I want to do in the next video is that we'll come back and turn the color back to white when we
take away those Kalama because out of the sayne.