OK let's have a look how this project is put together.
Now the GOP is control itself.
It's still there.
There's no compass needle anymore.
I've taken that out of the wicket shoot camera and an image trick I set up as we've always set up in
the past.
So in the controller code if we just go in there because the compass needle has been taken and in the
update to stop it from giving you an area you can either put I know all around the compass needle to
check whether it exists or not.
And and then do this law in or as I've done I've just commented it out so it's not going to be trying
to work with that compass needle.
Now back in unity if we go into a folder I've got called directions let's just have a look in there.
So I've brought in those meshes that are in the zip file which were e an S and W.
If you go to your trackable item making sure that in the image checker you've set up the Target collection
as the compass WTC then hit preview and find that in your scene and then grab one of these letters and
put that as a child to your trackable you can see where it is.
And you'll notice that it appears off to the side.
So that's how it would come up in the augmented view.
Now that's fine if you want to look like that is going to look a lot.
Nature if it sits in the middle so instead of that an eye manipulated by moving it across a little bit
like this and then making a pre-fab out of that which is called in prefab.
That's what I got to have everything sitting in this folder.
And if we just get rid of that and don't assign it to anything and put my in prefab in there you can
see that it's in the right spot where I want it.
And of course you can also resize it if you'd like.
Of course you'll want to go through this same process with each of the other letters as well so that
they line up with the marker.
Now we don't need that in prefab that we added before.
So just delete that out of the hierarchy.
And now let's have a look what's in that compass direction code that's attached to the trackable.
So it's Simula and based on the previous code that we used in the last lecture where there was an array
of objects being displayed we have the array at the top which is public so it's exposed in the inspector
which will allow you to put your prefabs in there for the north south east and west modals all letters
that you want to appear on that compass tag.
We then have another array of these things after I've been instantiated.
So we'll do the same thing again.
We will instantiate each one of them attach them to this object which is your trackable so that the
trackable is the parent of them and then just sit them all to be inactive until they're needed.
Now this next launch is for lost direction on.
This is an index into this array for which object was last displayed on the mockup.
The reason being is that this Mocca is going to change from one object to the other but not instantly
from one object to the other.
You'll only get like in the north when you're within that 20 degree range of the north heading.
And when you're out of that and you're not facing 20 degrees close enough to any of the other directions
you want absolutely nothing appearing on there.
So in order to turn off the last thing that was displayed I'm keeping a track of which one of those
things it was just to make it a lot more elegant in the code as to how we turned it off.
You cool it after you've got out of any of those ranges turn everything off and just you know cover
all of your biases which is fine in this case because you've only got four things so let's vises not
going to be a lot of processing power taken up by that.
But as I said this is probably just a little bit nature and if he did have a really large array of objects
you want to do display then this would be much more efficient to do it this way.
Now in the start it's the same as we've had before except I've got the prefabs a called direction prefabs
instead.
So first of all we set the objects are right that we need to hold all of our instances to the same size
as the number of prefabs that we've got.
And then we loop around that many times and create the mole so we instantiate the prefab using the prefabs
own position that we stored with it.
Now after each object is instantiated we then said its parent to this object is the transform.
So this is trackable.
And then after that we set it to be false so that we can't see it and it's not turned on.
OK so that is our start which is pretty familiar I would say by now.
Next we have a little method.
This method is going to turn the object on or off.
So it's a modification of the previous version of this method where this time we can pass through an
on day of minus one and it will actually destroy the last direction on object or not destroyed I should
say it will turn it off so that you can't see it.
So when we go out of range of a heading then we just call this method with minus 1 and it will use whatever
used to be turned on and just turn it off and then return from this.
Stop looping around everything.
The remainder of this code is the same as it was previously.
First of all we check if the one we're trying to turn on is active.
If it is we don't bother doing anything else.
Otherwise we then do this little loop where we go through.
We check the index into the array against ID which we passed through.
If they're the same this is the one we want to turn on.
So let's turn it on.
Otherwise we're going to turn it off.
Now I guess logically speaking we don't need to do this turning off thing because it will naturally
have been turned off when we went out of range and cold.
Minus one up here.
So you could possibly do without this.
Else statement in this case.
Now this is called from Updike.
Now it's probably update and all of the different logic that you had to come up with for the bans on
the side of your hating that might have tripped you up.
So here is what I've got.
Let's go down into day two and get it on the screen.
OK.
Good.
So we want out.
GVS control ADOT heading remember this is now a public static so we can address it like this in here.
If it's greater than 350 and it's also less than 10 then that's when we're facing north.
However because the way these compass coordinates work it's always really funny around that zero point
because you don't go from a negative value to a positive value you go from like 350 non And then you
pop straight around to zero.
So in this case to combine the two values that you're testing for you need to have an OR statement so
it needs to be greater than 350 or less than 10.
Then we turn on object zero which we will make sure we give it the north model for that.
At the same time we turn the object on we will set lost direction on to zero.
So that these value knows what's on and it will then turn it off when asked to now the remainder of
the else if statements are just between two values that are continuous and therefore we use an end statement
we don't need to use them all.
So we want it to be greater than 260 but less than two IGY.
So it's an.
And same for waste sorry.
Now the next one is the south.
So it's greater than one 70 and less than 190 than we do south which is a second one then for the east
it's greater than 80 and less than 100 and we use the third or fourth in that array coming through there.
Now I've just noticed that my numbers are out of sequence here in my code.
Let me just fix step 1 and 3 for the last ones that are turned on.
Now in this else if we're not inside of these headings then we're going to turn off whatever was last
turned on with this and that will make sure that it now disappears from view.
So if we turned on North Up here we saved last direction on as the North value we get Dan here we turn
on object minus 1 and that will then sit inactive for North and make it disappear.
All right.
And that is the end of the code.
So now back in unity you want to select your trackable object that you have the compass direction script
attached to and you want to put your prefabs into the correct places based on how you using them inside
of that update.
As far as putting North on north and west on West et cetera.
So I remember in the directions folder that I've gosh I created the prefabs earlier.
The first one is going to be on North prefab.
The second one will be a west the third the south and the Fonua on the fourth one will be the east prefab.
Now you're ready to build it all out and test it.
Now don't forget before you do that you need to add in your Bondel ID and you also need to put in your
wicked chewed cameral license key and yet they go you should now have built an old Mantid reality application
that uses the compass inside of your device to switch between the different augmented objects.