This is a terrible system to work with and I just want to work in an environment where world wrapping is inherent. When I enter out from either end I disable the copy collider and teleport the player to the other side. Then I use a more complex form of teleportation where when I'm touching the edge of the screen I instantiate a copy of my collider and offset it to the other end of the screen. I need to set up 4 extra cameras on each edge of the screen to capture everything that's out of view and render it on top of the main screen. In addition, the setup and frankly the whole solution is faaar from ideal. I've gone the length to make it work for the most part but it's clunky and prone to bugs. Then I'm gonna need a more complex logic to, again, "fake" the wrapping. Like what if I want to wrap a long object through both halves of the screen. In addition it can limit to what extent you can go with wrapping objects. You can "fake" the logic in any game engine by teleporting the player between the edges, which is what most people do, but obviously that can create unwanted behaviour like spawning inside other objects. Here’s what function Start() contains: function Start () else if( < -4.World wrapping means looping from one end of the screen to the other like in A LOT of classic arcade games. The first one is called only once during all the scene play, and the second is called on each game frame (if MonoBehaviour is enabled). So its type will be double.Įveryone who has some knowledge about UnityScript knows that it has two important functions: function Start() and function Update(). This variable will be incremented by small numbers, like 0.01. Its speed will be determined by a variable called walkingSpeed. Since the 2D space is a little bit small, we’re going to use small numbers along the axis. To move the player on the 2D Space, its coordinates have to change, depending on which axis it will move along. The scoreText and livesText GameObjects will display information about the scores and the remaining lives to play. In this case, we will use two integer variables called scoreNumber (for saving the player’s scores) and livesNumber (for storing the player’s remaining lives). Indeed, it’s a 2D Sprite that will move and change behavior according to the code we’ll look at shortly. So the only player in our game will be called ant and it will be a GameObject. It will start with these variables: var ant : GameObject Inside the Scripts folder, create a new JavaScript file and call it AntScript.js. In the first part, we’ll create the variables, giving them a name and type. This will contain all the necessary functions to make game run. Inside the Assets folder, create a new one called Scripts. This project will be written in UnityScript. The latest versions of Unity support only two scripting languages: UnityScript (which is similar to JavaScript) and C#. Make this object similar to the Score object and place in another corner. This text will show us the number of our remaining lives. Set a readable font size and place it at any corner you want.Ĭreate another Text game object and call it Lives. Let this new game object be called Score. Now right-click on the Canvas in Hierarchy view and choose UI > Text. In the Canvas Scaler (Script) menu, set the UI Scale Mode to Scale With Screen Size and Screen Match Mode to Expand. Most of the times this is a number between 0 and 10. Plane Distance should be any value between the distance of the background and Main Camera. Render Camera should be your default camera, Main Camera. In the Canvas menu, select Render Mode to be Screen Space – Camera. Right-click on an empty space inside the Hierarchy view and go UI > Canvas. Click on Ant in the Hierarchy view and add a Circle Collider 2D. I scaled width and height by a factor of 2 to make it more visible and easier to tap. Now import the ant_1.png image the same way. I’m using a portrait screen similar to mobile screens, 800 x 1280px. Drag this image inside the Scene window and stretch it depending on the screen size you’re using. Open this folder, right-click, choose Import new Asset and import the background.jpg image. Once the new project is ready, inside the Assets folder create a new folder called Images. Creating Game Scene, Canvas and GUI ElementsĬreate a new 2D project and name it as you wish.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |