Welcome back to part two of looking at the GPA in your device.
OK.
So have you had time to look at the numbers on the screen.
There might be a few things you've noticed as you've played around them.
First of all my update time and mine now taan 10 hours out of sync.
And that's because the update time is actually in Greenwich Mean Time.
So from the prime meridian point where is my time zone.
I'm actually used 10 hours in front of that.
So that means that mine now time showing on my computer system time is going to be 10 hours out so I
could have adjusted for that but I'm just getting an idea of minutes and seconds really of when the
update was done.
So depending on what time zone you boring you might like to add that many hours or take that many hours
off of the time that's displaying so that they do line up on the screen.
Now the other thing is the values of the longer chewed and the latitude.
What did you notice about them.
Well I hope you went for a little bit of a walk around to see how far you had to go to get your latitude
and longitude values to change remember one degree in the latitude and longitude is approximately 111
kilometers.
So just moving around your house you're going to find it very hard to get those values to budge.
But they do change by like point 0 0 0 or 1 sometimes from one end of the house to the other.
At least that's what I found.
Now also note you're detecting satellite signals and when you're inside they're not that great.
So what I've actually done to test this was go at my front door my show I'm standing out in the open
or I can see the sky and Tiger rating and then go and have a look at it again out my back door out in
the open to get some kind of a comparison point and to find out just how little the values that are
changing when I move like a matter of 20 meters or so.
Because if you're going to create an augmented reality experience in a close vicinity like that where
you want to turn things on and off based on where you GPA wise then you're going to be working with
really tiny little numbers.
So assuming that you are now pretty much know what the long Chewton letted chewed values around your
current location ah I'm going to set a little bit of a challenge for you.
What I would like you to do is to put some code inside of this update that's going to bring up an object
on the screen when you reach a particular position whether it be a latitude position or a longer chewed
position.
And then when you leave that location make that object disappear from the screen.
So just use a cube or something.
In this case to see if you can get it to work.
So I pulls a video.
Now give that a bit of a go and when you come back I'll show you how to achieve it.
So how did you go with that.
Here's an example of mine running.
I've used the we chewed shoot.
In this case to give you the illusion of augment and reality and objects popping up.
And so it's very much like the Pokemon scenario.
We get to a certain location and the Pokemon pops up.
And fair enough it's just a Cuban it's not moving around but it's moving towards that.
OK so how did I do it.
Well first of all I added that we could shoot camera into my sane and I deleted the existing camera.
There's no moccasin here I'm not using that sort of functionality at the moment.
I also I created a cube.
And what I did is I positioned it right in front of the camera.
So I found where the camera was in the same view.
You can see it over here.
And then I grabbed my cube and I moved it so that when you weren't playing it was still inside of the
viewing volume of the camera.
Now if there's no markers in the same for the camera to pick up and be moved with it's not going to
move and that keeps always going to stay there.
And because it's the wicked shoot camera you get the video fade coming in for free.
So this makes it look as though you've got menta environment even though that cube is fixed to the camera.
At least you can see it and you get the sense that you're moving and your Lu-Chu and latitude are therefore
changing because you are going from one location to the other.
So with that.
Q What did I do back in the code that open that up.
Pass it through as a public game object at the top.
Hiya.
And then all I've done is call ice it active on that cube based on my proximity to ice and latitude
and I've done that down in the update.
So let's go down and have a look in the update.
This is the code that I added.
So depending on where you are in the world and where you want to restrict the showing of your augmented
object too you can put different statements in here.
But what I'm saying in this case is if my latitude was greater than or equal to a certain value then
turn the cube on otherwise turn the key off.
And that's just going to flick it back and forth from being on and off based around whatever value you
put into here.
So that gives you an idea of how you could use these with augmented reality.
Now you know how to do that.
It's time for a challenge.
So how about you.
Now I can augmented reality experience that changes what is on a Mokka as you change geographical locations.
So you work at a couple of coordinates that can change in the distance that you're able to walk within
your closest vicinity.
And then program one mock to show either the bear or the granny based on where you pause the video.
Now when we come back I'll show you how I put it together.
So how did you go putting that together.
Now a number of different ways you could have done it.
You could have used to image trackers in your scene and turn them on and off using exactly the same
Mokka on H which is quite acceptable thing to do and just have a different drawable objects with them
or what you could do is just have one image track and write a little bit of code that swaps the prefab
that's attached to it back and forth between them based on your geographical location.
So that's the way I did it.
And I'll show you.
So I've added in the we could shoot camera.
Now I've still got exactly the same G.P.A. object with exactly the same G.P.A. control a script on it.
That of course is with the exception of the public cube that we created and we're passing through.
So you can remove that line of code and the code that then turned the cube on and off which was down
in the update method having that there I know that I'm starting up those location services because that's
what happens in that code and you need to stop those up in order to facilitate the operation.
In this app.
Now if you don't do that you would have to start up the JPFO location somewhere else doing it on the
trackable which is where I've got my code would not work because each time you would lose the Mokka
then remember the code won't be running and monitoring your location so having that as a separate thing
is really good and just keeping track of what that location is inside the trackable code is a better
way to go.
Now my code that I've got on my trackable is called Swap prefabs.
Let's have a look what's in it before we do notice.
I've used the bare Mokka that we use.
I think it was the first tutorial again so you can just use any Mokka that you like.
And there's no durable object that holds the script doing everything.
And let's have a look at that.
So here it is.
Go to the top.
Usual libraries don't forget to include.
We could choose because we are using the image trackable then we have two public variables at the top.
We have bet and Graney.
So they the two prefabs that are getting passed through.
And you saw that down the bottom of checkable down here.
So there the Teti and granny prefabs that came previously with other exercises and are also attached
to this as a resource the game object for beer.
Object is the instantiation of the bat and granny object is the instantiation of Granny.
So what I'm going to do is create both the base objects from the get go but just sit them inactive until
they're needed.
And I'm also going to hold on to the image trackable item here because it's going to become the parent
for these objects here now in Stosh is where I'm doing this.
So the bear object is instantiated at the base transformed position make sure that you've got that for
that prefabs to zero so that it will center itself on your marker and then go to zero rotation.
The best option is having its parent sit to the start transform so it will be this trackable item that
becomes the parent.
So essentially you'll making a drawable.
OK you just doing it the long way around.
We can't access the durable of the image trackable after Stosh and swap it in and out.
So if you ever want to do anything with the image drawable So let's say up and start you want to change
what the drawer bull was.
You can get it just there.
But the problem is this is holding on to your prefab that you want to instantiate a lot on the market
comes in and out of visibility.
You can't do that in update.
Well you can do that an update but it doesn't do anything.
You can set it in stot which is when the Mocca first becomes visible.
But if you want to keep an object on the MoCCA and cake swapping it in and out as you're moving around
then you can't do it with the drawer.
And you might have actually tried that.
So let's get rid of that.
OK so we're setting the base object to false as far as being active then we're doing the same thing
with Graney.
We're going to instantiate Graney at Granny's zeroed heartfully position of the prais fat zero rotation
set.
Granny's parent to be this object.
And then make Greaney inactive as well.
Now what's the update that will do all of the checking for us.
And he pretty much got what I had before as far as turning the cube on and off but this time I got two
objects to take care of.
So I'm testing for a certain latitude being greater than or equal to that lot of Ceri.
And then if I am greater than or equal to that latitude then the bag becomes visible and granny gets
turned off.
Otherwise I want granny to AP on MoCCA and the bet to be turned off.
So this is just a little switch that's going to switch back and forth as you change latitudes across
this particular threshold.
And there's no reason why you couldn't have a more complex if statement in he with logic for latitudes
and longer choose or being within a certain range as well.
OK so that is the what prefabs that's going to change what's on the same Mokka based on your geographical
location.