So far in this two part lecture we've learnt how to turn color on our cars with different markets.
Now we're going to turn off the color so you'll need to go back into your color controller code and
we're now going to write the part that goes in on image last so above the de-bug.
Let's just add this in here it's very similar to what we had above as far as grabbing hold of the Mischer.
And the materials.
But instead of worrying about what the market color was we're just going to set the color straight to
White.
So we do what we do before we get all of the cars that are in the same tagged with CA.
Then the age of these cars we get hold of the list of materials that are attached to the mesh render
out which will be some way in the children of these vehicles.
Now I just want to stress again if you find you have a different model that you're using other than
these vehicles you will have to make sure that you're getting the right component.
Now this may work because you are looking for a mesh renderer to get the materials off the mesh renderer.
That's how it's going to make it show on the screen anyway.
It might just be that the Michigander is on the top level object itself and not buried in the children.
So just be sure that you're actually getting a Mischer under in this case.
And it's something to check if it's not working for you.
Now once we get to these materials which then loop through all them and we set them to white and that's
all we need to do so just say that and we'll switch back to unity and give it a go.
So press play there and we need to get a marker and find out ka
put the car over there and let's switch it to red
and then we can turn it off by getting rid of the marker out of the scene
OK so that's working really well now.
And let's try a Blue says the Mokka that causes me the most grief
and there we go OK.
So what are we going to do next.
Is a bit of a challenge.
Have a think about how you might do this and then try and implement it.
We want to have another Mokka create your own Machi around MHRA pig and use it to turn the cow lot on
and off.
Pause the video.
And when we come back I'll show you how to achieve that.
So how did you deal with that challenge did you get the lights to turn on and off with the new Mocca.
Well I'm going to show you how I've done it.
And you might have done it slightly differently and that's fine.
It's all about getting it to the stage.
So I've created a Jay Pay lots.
Jay peg here and you might have created your own which would have looked very different.
I imagine you would have found this to attach as a racehorse to this lecture if he had a look.
So it's a three star one.
And if I go to a window WTC Ed. car magazine I've already added mine in this ad to add it.
You click on Add and then you find it in the list.
Then you come back and hit the Apply button.
And if you have a look at lots it's a good quality with three stars.
Now that's already in the car magazine so that'll get loaded automatically in your image tracker.
And if you click on any of the targets underneath you'll see that it pops up inside of there.
Now we want to make it and another active target so I'm going to get to the bottom here.
And control day to duplicate that blue and ocal lights and then I will also be here in the inspector
for the lights turned the lights on and turn that blue off.
Now we've got six things to track so if I go back up to the tracker I can change the concurrent targets
to six.
Now at this point we get a little message that says having more than five concurrent targets can have
a negative effect on performance which is very true.
The more images that you're trying to find inside your camera fade the more work the algorithm has to
do.
So it'll start to get really slow as you add more and more.
We should be all right with six.
Or you could turn off your other cars at this point if you don't want those on.
Right so we've got that what do we need to do next.
Now you need to create a light control of script.
So I did hear let me open it up and you can have a look what's inside and it's got to the top.
So we have the libraries that you need to include then it's a classical light control law which extends
Monir behavior inside of the on image recognized.
It's going to find a cause then it's going to look through all the cars then it's going to grab all
of the lights that are in the children of those cars.
So you have to get multiple lights because each car has two locks attached to it.
Now I'm turning these lights off by setting the intensity to zero when they want to be on set the intensity
to one when you see the lights image.
I want the last to be on.
So in this first method at the top the loop around the lots is going to grab each one and just set its
intensity value to one.
Then in the image lost which is exactly the same code you can just copy and paste it from above it feel
like it's going to sit the intensity to zero or so it turns it off again.
So that you control a script.
Now we need to add that into our hierarchies so we will add an empty in here and we will call that the
launch control.
Like that and attach a lot controller script to it.
Now we go back to our lot trackable and we then give it the lie control law for the object that we're
running the script from.
Not the color control as we've got because we copied this from blue.
So put that law control into both of these areas and then you'll need to find the functions for recognized.
And the one that's in there for last.
OK so now we are ready to test this this press play.
First of all we need to find out Ka
and put it somewhere that you can see it's lots then we get al lot Marco and that will turn the lights
on.
Remember And you can turn them off by simply turning the Mocca off.
Now see the little bit of jittery ness that's happening.
And you might have even noticed the very intensity of the bright lights.
That's because that down for a second wave still got on these objects planes.
Now I didn't remove these before but the red marker when it is active this plane will be instantiated
in the same.
So you end up with two.
Two planes and if those planes come Nia your Ka object the physics is going to react on them.
So the red the blue and the lots we really should just remove these planes because we don't want to
have a physics object in this case.
So anything and you're saying that is related to physics is going to hit each other.
And so if you have several cars in the scene at once you draw them separately then they are going to
collide with each other within the physics system.
All right so that's how to turn the lights on and off how to add another Mocca into the same set of
markers and to have multiple controllers that are doing different things.
Now I wonder how many of you actually use the color controller for the law.
It's untested tested if it was called Lights So remember back in color control where is this remember.
Up here we tested for the target nine for red and for blue.
We could also put another else in.
Test for the target name equal to lights and then do something different as well just in this same lot
of control a code that would work equally equally as well.
The only difference being that the way I've done separates out the sort of the functionality of the
code and if you wanted to reuse it on something else is.
So they both got different purposes in this case.
OK.
So that's the end of this two part lecture.