Posts

Now create a new script, the reason for this is to create a script that will destroy the asteroid explosions since they are permanent since they cant be destroyed by boundary or trigger, name the script DestroyByTime Public class DestroyByTime : MonoBehaviour { Public float lifetime; Void Start () { Destory (gameObject, lifetime); } } Back in unity prefabs VFX explosions select the explosion asteroid, add component, scripts and select DestroyByTime   then set the lifetime to 2, do the same for the remaining explosion prefabs this means that the explosions are no longer crowding the scene which will have an impact on performance should things get out of hand, this code helps keep it in order. Audio is a large part of video games especially when it comes to immersion and can make a game, of course I can’t make the audio from scratch but using unity store assets I picked a few pieces of audio to use in this project. Select the explosion asteroid prefab so that ...
Now to create a game controller start by making a new game object and name it Game Controller and set it to origin position and change the tag to Game Controller and add component, new script and name it game controller, now edit the game controller script. Public class GameController : MonoBehaviour { Public GameObject hazard; Public Vector3 spawnValues; Public inthazardCount; Public float spawnWait; Public float startWait; Void start () { StartCoroutine (SpawnWaves ()); } IEnumerator SpawnWaves () { Yield return new WaitForSeconds (startWait); while (true) { For (int I = 0; i < hazardCount; i++) { Vector3 spawnPosition = new vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z); Quaternion spawnRotation = Quaternion.identity; Instantiate (hazard, spawnPosition. spawnRotation); Yield return new WaitForSeconds (spawnWait); } Yield return new WaitForSeconds (waveWait); } } } Select the Game Contr...
Now that the script is set up we can remove the Mesh Renderer and Cube (Mesh Filter) components. I decided to add some space debris to keep things interesting as well as boost score, to do this add new game object and rename it to Asteroid and set the transform Z-axis to 8. Taking an asteroid model from the models folder drag it to the Asteroid parent object in the hierarchy making the asteroid model a child. Select the Asteroid parent and add component physics, rigidbody and deselect use gravity then add another component physics, capsule collider then alter the collider to match the rough size of the asteroid. With the asteroid game object selected add component, new script and rename it to RandomRotator. Open this script and edit it Public class RandomRotator : MonoBehaviour { Public float tumble; Void start () { GetComponent<rigidbody>().angualrVelocity = Random.insideUnitSphere * tumble; } } Select the Asteroid parent and set the tumble value to 5 an...
Create a new empty game object and rename it to Bolt and reset its transform then create a quad and name it VFX and reset its transform as well them add it as a child of bolt. Change the transform rotation X-axis of VFX to 90, to rotate it upwards to the camera. Now we need an image for the bolt, in the materials folder create material which makes a new material in the materials folder and rename it to fx_bolt_orange. Next drag the texture onto the newly created material to apply that texture to it. Now drag the material onto the quad. Once again, we need to change the shader of the material to particles, additive. Now select the Bolt parent and add component, physics, rigidbody and deselect use gravity, reselect VFX and remove the mesh collider component then back to the Bolt parent and add component physics, capsule collider. Change the direction to Z-axis then resize the collider via the radius and height to match the Bolts size and select the Is Trigger box. Still in the Bolt par...
Create a new folder in assets and name it Scripts, Then click on the player in the hierachy and add component scripts, new script. and name it PlayerController, then drag and drop the script into the Scripts folder and open it up in monoDevelop. Remove the sample code. [System.Serializable] public class Boundary {   public float xMin, xMax, zMin, zMax; } public class PlayerController : MonoBehaviour { public float speed; public float tilt; public Boundary boundary; void FixedUpdate () { float moveHorizontal = Input.GetAxis ("Horizontal"); float moveVertical = Input.GetAxis ("Vertical"); Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical); GetComponent<rigidbody>().velocity = movement * speed; rigidbody.position = new Vector3  (  Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),   0.0f,   Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax), ); ...
Now to add a background that is not just a black void, which while space is it is not very interesting for a game world. Click on the player in the hierachy and deselect or uncheck the box next to the player in the inspector just so that it is not in the way. Then create 3D object, quad and rename it to Background, using the scene view so that it is visable and reset its transform and set its rotation X-axis to 90 this will make it visible in the game view though it is not necessary to use that view at the moment stick with scene view and remove the quads mesh collider component as it is not required. now it needs a texture, now to scale up the quad by changing the scale X-axis to 21 and Y-axis to 21 so that it fits into the game view nicely, if you were using a texture with an image resolution of 1024x2048 you would want to have the scale X be half of the Y-axis so an example would be X 15 and Y 30 to make sure the image does not become blurry. Next to add some lighting to the bac...
Now for my most enjoyable part, setting up the camera. Start by selecting the Main Camera in the hierarchy and resetting its transform in the inspector, we do this because we want the view point of the player to be top-down so having it in the origin point helps this process. Then rotate the X-axis to 90 degrees, next in take the Y-axis of position and set it to 10 and this should give you a decent view. Now for the camera component, change the projection from Perspective to Orthographic and using the Game view and set the size to 10 then to make sure the ship is not in the center view of the camera change the camera position along the Z-axis to 6 and then change the Clear Flags to solid color i then set the background color to black so that there will be some cinematic arcade black borders. Next select create, light, directional light and rename it Main Light and reset its position so its at the origin point, then reset its rotation to 0 then set the X-axis to around 20. Then chang...