Showing posts with label Interactivity. Show all posts
Showing posts with label Interactivity. Show all posts

Monday, 16 March 2015

Interactivity - Building the game


  • open build settings window 
  • click build and make a new folder and name the game


Thursday, 12 March 2015

Interactivity - Customising the game

So i changed a few things on the game

i decided to make it simpsons themed so i changed the  background to the a picture of the simpsons kitchen, as this was landscape i the had to change the size of the plane, the camera and game view



I then changed the ship to a plan and added a picture of homer simpson, at first he was a white back ground so i changed the shader to transparant so it was just his head 

I then had to make new asteroids to look like vegatables 

I then added 2 lots of bolts to the player as i wanted them to look like they were coming from his eyes 
to get this to work i had to change the player control script 
I also added a high score to the game by using this code 

I added a 2nd set of asteroids in the game , by creating a 2nd asteroid prefab and changing the game controller script to this 


which allows me to change the variable in unity so i can have as many asteroids as i like 

I then changed all the sounds to sounds that fit the game

I then duplicated the scene to create another level, this one is harder as the asteroid move alot faster 


As the asteroids on the other level had different values to this one i had to duplicate thoose too and re refference them in the gam controller script 


I then created a main menu so the player can choose what level they want to play 

to do this i created a new scene with a background camera and lighting 

i then created 2 ui buttons one for normal and one for hard 

To get the buttons to work i had to make a new empty game object called manager and apply this code to it 
then on the button  where it says on click  i sent it to the manager and the script applied to it and depend on what button it pressed it went to  a different scene 

to work out what scene number it was going to i went into the build settings then applied my scenes into the scene build 

i then made an exit button on each scene that took you back to the main menu 

here is what the game looks like now 


There is still alot more stuff that i want to do to my game like a health bar, mute sound, special asteroids, but so far i think its pretty good. 












Friday, 6 March 2015

Interactivity - Ending the game


  • create an empty game object add child the score text to it 
  • create 2 new gui texts one for restart and one for game over and adjust the text and move them into the center of the screen  
  •  make sure they are a child of the empty game object 
  • update the game controller code so it now looks like this 


  • then in unity add refferences to the text objects in the script 
  • open the destroy by contact script  and add the new lines of code in so it looks like this 

Wednesday, 4 March 2015

Interactivity - Audio and points



  • put the project window into a single coloum layout this way was can drag sound onto the assets easily 
  • select the explosion astorid pre fab and drag the explosion sound onto it in the inspector  and select play on awake
  • do this for all explosions and then add the Shooting sounds onto the play game object in the hierarchy ( on the player game object deselect play on awake ) 
  • to get the shot sounds to play go into the game controller script  and in the void update write  audio.Play (); 
  • then add background music to the game controller object and select play on awake and loop 
  • then turn the volumes down to what sounds correct 
  • create a new gui text and call it score text  in the text box write score text and move it to the top left corner 
  • open the game controller script and wrtie  public GUIText scoreText  private int score;
  • void UpdateScore ()
        {
            scoreText.text = "Score: " + score;
        }
 void Start ()
    {
        score = 0;
        UpdateScore ();
        StartCoroutine (SpawnWaves ());
    }
   public void AddScore (int newScoreValue)
    {
        score += newScoreValue;
        UpdateScore ();
    }
the script should now look like this 
  • open the destroy by contact script and write 
 public int scoreValue;
    private GameController gameController;
 void Start ()
    {
        GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
        if (gameControllerObject != null)
        {
            gameController = gameControllerObject.GetComponent <GameController>();
        }
        if (gameController == null)
        {
            Debug.Log ("Cannot find 'GameController' script");
        }
    }
the script will now look like this 

change the score value on the asteroid that contains the destroy by contact script 
and refference the score text object made on the game controller object 




Tuesday, 3 March 2015

Interactivity - Spawnign waves


  • open game controller script 
  • add 
  • in unity go to the game controler and change the variables of the script to this 
  • to get rid of the asteroid explosions from the hierarchy we need to write a new code
  • create a new script in the script folder called destroybytime and write 
  • save and add this script to the  explosions prefab and make the life time 2 

Monday, 2 March 2015

Interactivity - Game controller


  • create a new game object called game controller 
  •  tag the object as game controller 
  • add a new script to the game controller 
  • add this code 
  • in unity set the hazard and the spawn point location, as i have 2 hazards in my game this looks a little bit different  but i will explain that in a later post 

Saturday, 28 February 2015

Interactivity - Asteroids


  • create new game object, name it asteroid, set to origin then move it to z 8 
  • select asteroid model from model folder and drag onto asteroid in the hierarchy so it is a child of the game object 
  • add a ridigidbody, turn gravity off and add a capsule collider, scale to the size of the asteroid 
  • you can make the asteroid spin by using the code bellow how ever for my game i did not need to use this 
  • add a new script to the asteroid component called destroy by contact 
  • write this code 
  • then go back into unity, go to the bounday object int he hierarchy and tag it as bounday 
  • open the destroy by contact script again write 

  • save and go back to unit, click on the asteroid prefab and in the inspector  where the destroy by contact script is add the explosion prefebs to it the add the mover script on to the asteroid game object 
  •  then add the mover script on to the asteroid game object and set the speed to -5  
  • go to the player game object and tag it as player 
  • drag the asteroid from the hierarchy into the pre fabs folder and then delete the asteroid from the hierarchy 

Thursday, 26 February 2015

Interactivity - Boundary

So when you shoot bolts at the minute the just stay in the hierarchy so to stop that we are creating a boundary that destroys them
  • create a cube, scale it to the size of the game area then delete the mesh renderer , select is trigger on the box collider 



  • create a new script called destroy by boundary and add it to the boundary cube 
  • write this code 


Wednesday, 25 February 2015

Interactivity - Creating / shooting shoots

Ignore the fact i customised the look of my game becuase im going to talk about that more in a later post. 


  • create a new empty game object , call it bolt and reset it to origin 
  • create a quad to hold the image, call it vfx and move to origin, make this a child of the game object bolt 
  • make the trasformation of the quad x 90 
  • select materials folder, create new material, re name it blot orange , select material from asset picker 
  • drag  material onto quad, change the material shader to particles additive  to remove the black
  • add a physics ridigid body to the bolt, turn off gravity, then a capsule collider and resize to the shape of the bolt, select is trigger 







  • select the blot, add component, new script called mover 
  • Add this code  
  • save, check for errors
  • drag bot into pre fabs 
  • in prefab select bolt, make speed 15 
  • delete bolt from hierarchy 
  • select player , open player control script , add this code 
  • save it and go back to unity 
  • create a new empty game object and child it to the play , name it ShotSpawn
  • position the shot spawn to where you want the bolt to be fired from 
  • click on player 
  • go to player control script in inspector 
  • add bolt prefab on to shot 
  • add the shot spawn to the shot spawn 
  • and make the fire rate 0.25 
  • save