Posts

Showing posts from May, 2018
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...