Reader small image

You're reading from  Unity 2022 Mobile Game Development - Third Edition

Product typeBook
Published inJun 2023
Reading LevelIntermediate
PublisherPackt
ISBN-139781804613726
Edition3rd Edition
Languages
Tools
Right arrow
Author (1)
John P. Doran
John P. Doran
author image
John P. Doran

John P. Doran is a passionate and seasoned Technical Game Designer, Software Engineer, and Author who is based in Incheon, South Korea. His passion for game development began at an early age. He later graduated from DigiPen Institute of Technology with a Bachelor of Science in Game Design. For over a decade, John has gained extensive hands-on expertise in game development working in various roles ranging from game designer to lead UI programmer working in teams consisting of just himself to over 70 people in student, mod, and professional game projects including working at LucasArts on Star Wars: 1313. Additionally, John has worked in game development education teaching in Singapore, South Korea, and the United States. To date, he has authored over 10 books pertaining to game development. John is currently a Technical Game Design Instructor at George Mason University Korea. Prior to his present ventures, he was an award-winning videographer.
Read more about John P. Doran

Right arrow

Integrating Social Media into Our Project

We now have all of the foundational things needed to get our game out into the world; it’s mechanically working and we’ve set up all of the monetization. Having all of the features that we have added to our project is great, but if no one is playing your game, there’s no reason to have them.

Word-of-mouth marketing is the most reliable way to get others to try your game. Providing people with opportunities to share the game helps others discover the project, and it’s something that we should really try to do because marketing and getting your game out there is one of the hardest things to do as an indie developer.

In this chapter, you will learn some of the different ways to integrate social media into your projects. We will start off by adding something to share – a score. Afterward, we will see how we can share the score on Twitter. Then, we will see how we can connect our game to Facebook and use...

Technical requirements

This book utilizes Unity 2022.1.0b16 and Unity Hub 3.3.1, but the steps should work with minimal changes in future versions of the editor. If you would like to download the exact version used in this book and there is a new version out, you can visit Unity’s download archive at https://unity3d.com/get-unity/download/archive. You can also find the system requirements for Unity at https://docs.unity3d.com/2022.1/Documentation/Manual/system-requirements.html in the Unity Editor system requirements section. To deploy your project, you will need an Android or iOS device.

Unlike previous chapters, the use of the Facebook SDK requires both iOS and Android build support for your Unity version installed, so make sure that both are added before importing the package or you will have errors.

You can find the code files present in this chapter on GitHub at https://github.com/PacktPublishing/Unity-2022-Mobile-Game-Development-3rd-Edition/tree/main/Chapter08.

...

Adding a scoring system

In order to provide an incentive for players to share our game with others, we need to provide a compelling reason to do so. Some people are very competitive and wish to be the best at playing a game, challenging others to do better than them. To help with that, we can allow our players to share a score value via social media. However, to do that, we’ll first need to have a scoring system. Thankfully, it’s not too difficult to do that, so let’s add that real quick using the following steps:

  1. Start off by opening the Gameplay.scene file located in the Assets/Scenes folder of the project. To show our players what their score is, we’ll need to have some way to display it on the screen. In our case, the easiest way would be with a text object.
  2. From the Hierarchy window, select the On Screen Controls object that is the child of the Canvas object. Afterward, right-click on the On Screen Controls object and select UI | Text &...

Sharing high scores via Twitter

Twitter is an online news and social networking service where users post and interact with each other through messages that they call tweets, which are limited to 280 characters. Many indie game developers use Twitter as a way to attract others to play their games.

Twitter is a great option to start off with because we can add it very easily to our project by simply opening a specific URL. Let’s look at the steps to do just that:

  1. Open the PauseScreenBehaviour script. Once inside, we will add the following code inside the PlayerScreenBehaviour class:
    #region Share Score via Twitter
    /// <summary>
    /// Web address in order to create a tweet
    /// </summary>
    private const string tweetTextAddress = "http://twitter.com/intent/tweet?text=";
    /// <summary>
    /// Where we want players to visit
    /// </summary>
    private string appStoreLink = "http://johnpdoran.com/";
    [Tooltip("Reference to the player for...

Downloading and installing Facebook’s SDK

We couldn’t have a chapter on social networking without mentioning Facebook. Facebook has its own SDK that can be used with Unity. This can allow us to use the information that Facebook already has, including the user’s name and profile image, within our game experience. Let’s look at the steps to incorporate them:

  1. Open up your web browser and visit https://developers.facebook.com/docs/unity/:
Figure 8.9: Facebook SDK for Unity page

Figure 8.9: Facebook SDK for Unity page

  1. Click on the Download the SDK button and wait for it to finish downloading. Once it is downloaded, unzip it and then open up the facebook-unity-sdk-15.1.0 folder. Then, open up the FacebookSDK folder and you’ll see a single file, facebook-unity-sdk-15.1.0.unitypackage.

Unlike previous chapters, the use of the Facebook SDK requires both iOS and Android build support for your Unity version installed, so make sure that both are...

Logging in to our game via Facebook

One of the things we can do when using the Facebook API is to allow our users to log in to the game using their Facebook account. Then, we can use their name and image automatically within our project. The following steps show us how to achieve this:

  1. Let’s first open up our Main Menu level by going to the Project window, opening the Assets/Scenes folder, and then double-clicking on the MainMenu file.
  2. From there, let’s click on the 2D button to go into 2D mode if you haven’t done so previously. What we will do is replace the original menu and instead have a button for players to log in via Facebook, or play as a guest when the game starts.
  3. Go to the Hierarchy window, select the Canvas - Scale Physical object, and expand it and the Safe Area Holder child. Select the Panel child and rename it Menu Options.
  4. Then, select the Menu Options object in the Hierarchy window and duplicate it by pressing Ctrl + D. Then...

Displaying a Facebook name and profile picture

A good thing to do is to personalize our game to fit our players. So, with that, once the player logs in, we will welcome them and display their image on the screen by following these steps:

  1. Go to the MainMenuBehaviour script once again. From there, we’ll need to add a new using statement to display an image and change the text we need in order to use Unity’s UI system and TextMeshPro:
    using UnityEngine.UI; // Image
    using TMPro; //TextMeshProUGUI
  2. We will then need to add two new variables:
    [Tooltip("Will display the user's Facebook profile pic")] 
    public Image profilePic;
    [Tooltip("The text object used to display the greeting")] 
    public TextMeshProUGUI greeting;

These variables will hold the information that we wish to display once we get it from Facebook.

  1. Afterward, we will update the ShowMainMenu function and add some new functions to use:
    public void ShowMainMenu()
    {
     ...

Summary

In this chapter, we were introduced to some of the potential ways that we can share our game with others, as well as personalizing our game experiences and utilizing the functionality that social media provides us with. We started off by adding a simple score system and then allowed users to share their scores via Twitter. We then set up the Facebook SDK, making it so that we can log in to it to play our game and retrieve information about our users, which we can use to customize their gameplay experience.

Now that we have people playing our game, we want them to keep coming back and playing over time. One of the easiest ways to do this is through the use of notifications, which we will look at in the next chapter.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Unity 2022 Mobile Game Development - Third Edition
Published in: Jun 2023Publisher: PacktISBN-13: 9781804613726
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
John P. Doran

John P. Doran is a passionate and seasoned Technical Game Designer, Software Engineer, and Author who is based in Incheon, South Korea. His passion for game development began at an early age. He later graduated from DigiPen Institute of Technology with a Bachelor of Science in Game Design. For over a decade, John has gained extensive hands-on expertise in game development working in various roles ranging from game designer to lead UI programmer working in teams consisting of just himself to over 70 people in student, mod, and professional game projects including working at LucasArts on Star Wars: 1313. Additionally, John has worked in game development education teaching in Singapore, South Korea, and the United States. To date, he has authored over 10 books pertaining to game development. John is currently a Technical Game Design Instructor at George Mason University Korea. Prior to his present ventures, he was an award-winning videographer.
Read more about John P. Doran