![]() You can place in your scene, outside of the region which will be displayed in your device 2 empty game objects with a collider, so the player will crash against them. Vector2 rUCorner = camera.ViewportToWorldPoint(new Vector3(1f, 1f, camera.nearClipPlane)) ĮdgeCollider2D upperEdge = new GameObject("upperEdge").AddComponent() Ĭolliderpoints = new Vector2(lDCorner.x, rUCorner.y) Ĭolliderpoints = new Vector2(rUCorner.x, rUCorner.y) ĮdgeCollider2D lowerEdge = new GameObject("lowerEdge").AddComponent() Ĭolliderpoints = new Vector2(lDCorner.x, lDCorner.y) Ĭolliderpoints = new Vector2(rUCorner.x, lDCorner.y) ĮdgeCollider2D leftEdge = new GameObject("leftEdge").AddComponent() ĮdgeCollider2D rightEdge = new GameObject("rightEdge").AddComponent() Vector2 lDCorner = camera.ViewportToWorldPoint(new Vector3(0, 0f, camera.nearClipPlane)) This will generate edge colliders around the screen (for 2d): void GenerateCollidersAcrossScreen() I'm trying to solve it with a wall at the side of the screen. Image 1 is my Wall's and Image 2 my Player's. This is my code: public GameObject player Now my question is: how can my player gameobject collide with the side of the screen? At my player-Gameobject there is an edge collider. I tried to make a "wall" but I had no success. But he is just moving out of the screen at the left and the right side. There is a player in my scene and if the user tilts his device the player Object is moving on the ground. Now all I have to do is make the Asteroids spawn in from different angles of the screen, which I think is what I will focus on next time.I'm working currently at a 2D Game for Android. This is how the Script looked to start with (just to test out the spawn time for now, which I set the default to 3f which is when the first asteroid would spawn)…Īs you can see the spawning of the Asteroids were out of control!!! So in order to fix this, I added a new line of code in the ‘SpawnController’ script so that the spawning of the Asteroids were spawned in a more controlled manor… ![]() The script would later on be added to the main camera so that the every time the camera picked up the scripts functions, the camera would spawn the Asteroids now and again. As you can probably tell, this would allow me to spawn Asteroids in individually and separate from each other overtime, creating an action filled game (instead of just having one Asteroid flying around out of nowhere). Now it was time to spawn the Asteroids in by creating a new script called ‘SpawnController’. After I had done this, I made the Asteroid a Prefab and added it to the Prefab folder of my project. ![]() This was similar to how I made the spinning for my Spaceship but I didn’t want full control over the movement of the asteroid, which is why the random ‘Tourque’ function was added. But my main priority at that moment in time was to get the Asteroid to move, so to get that to happen, I did a similar type of layout in the script as the Bullet script I had made previously but applying it to the Asteroid to make it travel along the X axis, the result of this is shown below… ![]() This code was created so that eventually, when the Asteroid was hit, that it would split up into smaller asteroids and be destroyed, just like the original Asteroids game. So to start with, I added an Asteroid into my game scene and applied the appropriate components to it such as a 2D Rigidbody and a Collider (I used the Circle collider as I thought it best fitted the asteroid) and I also removed the gravity scale so that there was no gravity on the Asteroid.Īfter I had done this I then went on to create a new ‘C Sharp’ script for the asteroid named, ‘AsteroidController’. This was so that the player could shoot asteroids so that they could prevent themselves from being destroyed by an asteroid (which is the whole aim of the game). If you remember from last time I had created the player shooting and fire rate… Today I did more work on my individual Unity game. ![]()
0 Comments
Leave a Reply. |