From the course: Unity: Integrating GPS and Points of Interest

Create a scene controller

Okay, so, now, let's jump straight in and figure this out. Let's get rid of this little margin, down on the right hand side, where the scroll bar was, along with the one down on the bottom. Now, these two were basically just margins on the Viewport here. And it's for the scroll bars when the actual component is initially added. I mentioned that I wanted to demonstrate this Scroll View. I like them being about 370. I'll just resize that, to show you. There we go, like so. But it does distort the text and squash it down a little bit. So, it's up to you guys what you want to do. Maybe I'll just put it somewhere in the middle. Now, the other thing that you can do, from a cosmetic point of view, is, if you select the Content, we can add some Spacing. And you can add maybe 10 or 15 Spacing. And, if you press play now, that means it will have a slight gap between each button. And you'll be able to see the background through it. So, it is completely up to you guys. I mean, have a combination, if you want. Let's have 15 on the Spacing. And then, on the Viewport, if we had 15 on the Right or 15 on the Left, then, oh, well, let's add 15 to the top, as well. There we go, then these buttons actually float with a border. Which, I do actually like the look of. It's just that it's now cropping off the text. Which kind of messes it up for me. And then you'd have to jump into the button and resize the actual Width down, like so, to about 390. And, through here, 720. So, it's completely up to you guys. Let me just have a look at how that looks, in fact. I might keep this for the border. In the original demo, that I did for myself, I didn't have a border around it. But I think I quite like that, I'm going to do that. I'm going to have the Width at 720, even though the graphic's 750. It's not distorting the text too much, because we've shrunk the Height down, as well. Okay, now I've got the cosmetics sorted out, what I'm going to do is actually delete the buttons, because we're going to use a prefab instead. So, here is the button, I'm just going to rename this as point of interest. There we go, and we don't need the text that appears inside, that actually says the word Button. There, look, you see? So, we don't need that. So, I'm going to get rid of that, as well. Like so. Okay, then, cool. Okay, now, this button's going to be quite easy. All it's going to do is, when we click it, pass through a keyword and switch the scene to the list view scene. Okay, so, what we're going to need is we're going to need to create a script and attach that to an empty GameObject, here. And I'll just call this SceneController. There we go, and I'm going to add a new script now, called SceneController, like so. There we go, Create and Add. And then I'm going to jump to the top level of the Assets and drop that inside the Scripts folder. So, drop you into the Pack. And then, from the Pack, into the Scripts folder, just to keep things nice and neat, there we go. Okay, so, let's double click and open this up in Visual Studio or Model Develop, depending on which one you are using. And, like I said, the job of this is, basically, to switch the scene. We're also going to have the function to quit the application. And we're going to have the function to actually ping Google from here. So, it's a multipurpose script and all the buttons will have it attached to it. So, here we go, here is Visual Studio booting up. Still going, and we're done, right. So, if we're messing around with a scene. The first thing that we're going to need to do and a full list of different things that you can pass. And then the second thing that we're going to do, if I drag the SceneController back in again, is to simply call the changeScene. And although the scene doesn't exist yet, I'm going to name this listView. Okay, so, now what we're going to do is we're going to just simply save the file. And then I'm going to save the scene as the listView scene. Just as it is right now. So, list underscore View. And I'm just going to drop that inside the scene view, there we go. Okay, so, now, up at the top, you can't really see it, I'll just bring it down, it says listView up at the top. So, I'm now on the listView. Now, if I go back to the Scenes. I'm going to rename this one as main. Okay, now, on the SceneController, here, on Start, I'm just going to debug out the keyword from the top of the actual script. Okay, so, when we're on the main scene. Here we go, if I just switch to the main scene now. There we go, it's just switching. Right, that's done, it says main across the top. I'll just double click on the button, let's have a look. I'll just double click on the button, let's have a look. Yep, so, it should debug down at the bottom, in the console, Yep, so, it should debug down at the bottom, in the console, point_of_interest, if that static variable is working. point_of_interest, if that static variable is working. Because both scenes contain the SceneController. Because both scenes contain the SceneController. So, let's press play, it should debug nothing. So, let's press play, it should debug nothing. There we go, look, it says null, down in the corner. There we go, look, it says null, down in the corner. But, if I click through, there we go. But, if I click through, there we go. Ah. (laughs) Ah. (laughs) If I add the other scene to it, If I add the other scene to it, then I'll actually be able to switch through. then I'll actually be able to switch through. Let's add the new scene by going to File + Build Settings. Let's add the new scene by going to File + Build Settings. There we go, and what I want to do is just add the listView. There we go, and what I want to do is just add the listView. Which will then allow us to actually navigate through. Which will then allow us to actually navigate through. So, if I go to my project and just drag listView in, So, if I go to my project and just drag listView in, there we go. there we go. And now when I press play, And now when I press play, and we should be on the main scene, and we should be on the main scene, it should say null in the bottom corner, it should say null in the bottom corner, for when it debugs out that string. for when it debugs out that string. If I get rid of the arrows first. If I get rid of the arrows first. Sorry for this, guys, there we go. Sorry for this, guys, there we go. So, I'll just press play. So, I'll just press play. And here we go, it says null, in the corner. And here we go, it says null, in the corner. Take Maximize On Play off, actually, Take Maximize On Play off, actually, to make it a little bit easier to see the console. to make it a little bit easier to see the console. There we go. There we go. And then, now, when I click on Point Of Interest, And then, now, when I click on Point Of Interest, there we go, look, it's passed through from one scene. there we go, look, it's passed through from one scene. Because the variable's static, Because the variable's static, it will transfer through and be held in memory. it will transfer through and be held in memory. So, we can still access that variable So, we can still access that variable from a different scene. from a different scene. Now, all that we're going to do is override that, Now, all that we're going to do is override that, every time that this scene actually loads. every time that this scene actually loads. So, there we go, the debugging's work. So, there we go, the debugging's work. And I'll just save this now. And I'll just save this now. And I'll just go into my script for a second, And I'll just go into my script for a second, and delete that. and delete that. Okay, and just to make things a little bit easier Okay, and just to make things a little bit easier for us, in testing, if we open up the listView, for us, in testing, if we open up the listView, I'm going to add a little back button in the corner. I'm going to add a little back button in the corner. So, let's open up the listView. So, let's open up the listView. There we go, make sure it says listView There we go, make sure it says listView up at the top, up here. up at the top, up here. And then, on the Canvas, And then, on the Canvas, I'm just going to add another button, a UI button. I'm just going to add another button, a UI button. There we go. There we go. And position you into the top left, like so. And position you into the top left, like so. Let's have a quick look if there's a sprite we could use. Let's have a quick look if there's a sprite we could use. And we'll leave it at the default, why not. And we'll leave it at the default, why not. Just make it a little bit bigger. Just make it a little bit bigger. So, about 90, in Height, and about 90 in Width. So, about 90, in Height, and about 90 in Width. There we go, I'm just going to position this by eye. There we go, I'm just going to position this by eye. So, I'll just bring this down a little bit. So, I'll just bring this down a little bit. There we go, and off the edge slightly, about here. There we go, and off the edge slightly, about here. And then I'm going to go inside the Button And then I'm going to go inside the Button and change the Text to just be a back arrow, like so. and change the Text to just be a back arrow, like so. And increase the Font Size. And increase the Font Size. Now, if you want to, you can swap the button background Now, if you want to, you can swap the button background to maybe match the background blue a little bit more, to maybe match the background blue a little bit more, like so. like so. And maybe change the text color And maybe change the text color of the back arrow to be white. of the back arrow to be white. Now, so, now we have the button. Now, so, now we have the button. If we select the Button and we name this as back. If we select the Button and we name this as back. There we go, all that we need to do is, There we go, all that we need to do is, if I just zoom out slightly, if I just zoom out slightly, I'm going to come down and I'm going to, I'm going to come down and I'm going to, on the click event, for the back button, on the click event, for the back button, drag the SceneController in again. drag the SceneController in again. And call the changeScene function, there we go. And call the changeScene function, there we go. And the scene that we're looking for is the main scene. And the scene that we're looking for is the main scene. Okay, so, save that and go back to main. Okay, so, save that and go back to main. There we go, so, now when I press play, There we go, so, now when I press play, we are on the main scene. we are on the main scene. There we go, I click through. There we go, I click through. The button appears, look, up at the top. The button appears, look, up at the top. And up at the top, here, it says I'm on the listView. And up at the top, here, it says I'm on the listView. And now I should be able to navigate back, as well. And now I should be able to navigate back, as well. There we go, the button's disappeared, There we go, the button's disappeared, which means I know I'm on the main scene. which means I know I'm on the main scene. Okay, fantastic, cool, save it. Okay, fantastic, cool, save it. And I'll see you in the next video, And I'll see you in the next video, where we make this a prefab and then move onto the GPS. where we make this a prefab and then move onto the GPS.

Contents