In this project you should set up a camera and an object you want the player to be able to move. Create a script and attach it to the object you want to move and open the script.
The first this we do is add the following line to the update method.
Here we pass in the transform of the moving object. ScreenPosition will contain values for the x, y, and z position of the object. These values will range from between 0 to 1. I found it easier to work with pixels so that's what we will convert it to now.
Next we need to find the width and height, in pixels, of the screen.
That's all the data we need to make sure the object always stays on screen. The next thing you need to do is check player input and then if the objects transform.position + movementSpeed is less that maxX/maxY and greater that 0.
The first this we do is add the following line to the update method.
No comments:
Post a Comment