Tag Archives: screen

Adding a UI to display the score in a 2D game with Unity

This tutorial continues on from the previous tutorial on adding collectables and scoring to a 2D Unity game. In the previous tutorial, we improved the points scoring system and added collectables (coins) of different values).

In this tutorial we will add a UI (user interface) which will display the number of coins collected to the user. The LevelManager script will be responsible for displaying and updating the score text on screen. Watch the video below and then scroll down for the sample code.

Sample code

Here is the sample C# code for the LevelManager script.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class LevelManager : MonoBehaviour {
  public float respawnDelay;
  public PlayerController gamePlayer;
  public int coins;
  public Text coinText;

  // Use this for initialization
  void Start () {
    gamePlayer = FindObjectOfType<PlayerController> ();
    coinText.text = "Coins: " + coins;
  // Update is called once per frame
  void Update () {

  public void Respawn(){
    StartCoroutine ("RespawnCoroutine");

  public IEnumerator RespawnCoroutine(){
    gamePlayer.gameObject.SetActive (false);
    yield return new WaitForSeconds (respawnDelay);
    gamePlayer.transform.position = gamePlayer.respawnPoint;
    gamePlayer.gameObject.SetActive (true);

  public void AddCoins(int numberOfCoins){
    coins += numberOfCoins;
    coinText.text = "Coins: " + coins;

Adding a Details screen to the List app for iOS with Xamarin

In this tutorial, we will look at how to extend the iOS List app we made in the previous tutorial by adding a Details screen that will display more details about item the user has selected from the list.

This is what the app will look like…


Note: The title bar of the app will normally display and should be presented when the app is tested on an actual iOS device, but a bug in the iOS Simulator used here prevents the title bar from showing.

Step 1

Drag a Navigation Controller from the Toolbox on to your storyboard.


Right-click and Delete the Root View Controller that is not required (you may have to delete twice).


Step 2

Hold down the Control (Ctrl) key while clicking and dragging from the Navigation Controller to the Table View screen. Then select Root.


Step 3

Drag a View Controller from the Toolbox on to your storyboard next to the main screen.


Step 4

Add an ImageView element and a Label element to your screen. The default Text value for the label can be set to City Name. You also need to give both elements a name. Set the Name value for the Image View to cityImageView and the Name value for the label to cityNameLabel.

When you give the ImageView or Label element a name you will see a yellow warning icon in the Name field. Click this icon and then type in DetailsViewContoller and press the Enter key to generate a new class and codebehind for this screen.


Step 5

Now Control-click (Crl + click) and drag from the row on the main screen to the new details screen and select Show. This means that when the user selects a city from the list, they will be taken to the city details screen.


You can also double-click on the main screen’s title to change it.


Step 6

Click on the arrow between the main screen and details screen. On the Properties panel, set the Identifier value to DetailsSegue. Remember its name because it will be used in the code.



Step 7

Open the CitiesViewController.cs file and scroll down to the City class. We need to add a new property called ImagePath which will contain the image for each city in the class.



Step 8

Right-click the project folder and select Add > New Folder. Name this folder Images.


Now right-click the Images folder and click Add > Add Files from Folder.


Browse for the folder containing your images and then click Open.


Select the desired images and then click OK.


Select Copy the file to the directory and Use the same action for all selected files. Then click OK.


Step 9

Go back to the CitiesViewController.cs file and for each city in the cityList, add the lines highlighted below to specify the ImagePath for each city’s image. Remember to add a comma to the end of the line before the ImagePath line (see the commas at the end of lines 22 and 31).


Step 10

Go to the DetailsViewController.cs file and add the public City selectedCity; line to the DetailsViewController : UIViewController class. Save the file.


 Step 11

Now you need to add a PrepareForSegue override method. You can add this method after the GetCell method. Start typing public override PrepareForSegue and then select the PrepAreForSegue method from the list by double-clicking it or pressing Enter to autocomplete.


Step 12

Add the following code to the new PrepareForSegue method. This will check if the segue is the DetailsSegue (in other words, if the user tapped one of the rows from the table on the main screen that takes them to the details screen). Then it will get the relevant data from the selected row to be displayed on the details screen.


Step 13

Back in the DetailsViewController.cs file, add a public override ViewWillAppear method. To do this, start typing public override ViewWillAppear and then select that method from the list.


Step 14

Inside the new ViewWillAppear method (which runs as soon as the second screen loads), add the following highlighted lines of code (replacing any existing default code inside the method). This will set the label text to display the name of the selected city and will also set the ImageView to display the image representing the selected city.


All done! Make sure you save your files and then you can test your app!

You can extend this app by adding more properties to each City item so that the Details page can display more information about a city such as points of interest, activities, and even its location on a map.

In the next tutorial we will look at how to add thumbnail image previews to each row in the list.

Adding more screens to an iOS app

This tutorial explains how to add more than one screen to your iOS app and link screens together using buttons. We will use a simple example for this tutorial as show below…


Watch the video below or scroll down to read the step-by-step instructions and sample code.


Step 1

Start by creating a new solution (click File > New Solution).


Step 2

Give your app a name, select a minimum supported iOS version and click Next.


Confirm the project and solution names, the project folder location and click Create.


Step 3 

Open the Main.storyboard file and drag a Button element on to the screen. Give it a name and change its text value.


Step 4

Drag a Navigation Controller anywhere onto the storyboard. It should look like this…


Step 5

Right-click the Root View Controller and click Delete.


Step 6

Hold down the Ctrl (Control) key while dragging the Navigation Controller screen to your main screen (you will see a blue line linking the two screens together). The select Root from the list of options – this will make the main screen the root screen (the screen that loads first when the app starts running).


Step 7

Now drag a View Controller element onto the storyboard and place it to the right side of your main (root) screen. This will create a new screen which will be the second screen in your app.


Step 8

Hold down the Ctrl (Control) key while clicking and dragging the button on the main screen to the second screen. When you see the list of options appear, select Appear.


Step 9

Now we can add a Button to get from the second screen back to the main screen. Drag a button element on to the second screen. Give it a name. When you name the first element that you add to a new screen, you will see a yellow warning icon. Click it and then you will need to type in the name of the new ViewController for this screen  (for example, ScreenTwoViewController)– the name you provide will be the name of a new C# file that will contain the code for this screen. Change the Title property of the button the Back.


Step 10

Now click on the new button on the second screen. Hold down the Ctrl (Control) key while dragging this button to the main screen. Click on Show. This will make the Back button take the user back to the main screen when they tap it.


Lastly, double-click on the main screen’s title so you can rename it.


That’s it! Now you can test out your app.

Advanced Camera Techniques in Unity

In this tutorial we will look at how to add cameras to objects, how to set up a split screen camera system, and how to add a picture-in-picture (PIP) effect to your game. Scroll down to watch the video.

Adding cameras to objects are particularly useful for when you want to add a camera view to a character or game object eg. first person view inside a car.

Split screen camera systems are great for multiplayer games because you can have one player using the top half of the screen and another player using the bottom half of the screen. You could set up two cameras or you could have four cameras taking up the screen if you have four players in the game. Take a look at the example below.

Two players using split screen camera system.
Two players using split screen camera system.

Picture-in-picture (PIP) effects are great for maps and rear-camera views. For example, you could use a camera to display a map in the top corner of the screen so the player knows where they are located in the game’s world. You could also use a PIP effect to display a rear-view mirror so that a player can see behind their car in a racing game. Take a look at the example below.

A picture-in-picture (PIP) effect with a second camera view.
A picture-in-picture (PIP) effect with a second camera view.

We will also look at how to handle errors that you might see related to multiple audio listeners. To find out how to add cameras to objects, add split screen camera systems and PIP effects, watch the video below.


Green screen effects in Premiere Pro

This video tutorial explains how to use green screen footage with the Ultra Key effect in your video projects. This is demonstrated using Adobe Premiere Pro CC 2015 on Mac OS X Yosemite but the steps are the same on Windows.

Watch the video below and then try out the effect yourself. You can find free green screen footage on the web and on YouTube channels such as the Footage Island YouTube channel.