Book Image

Learning Unity iOS Game Development

Book Image

Learning Unity iOS Game Development

Overview of this book

Table of Contents (14 chapters)
Learning Unity iOS Game Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
6
Main Menu, iAds, Leaderboards, Store Purchases, and Achievements
Index

Creating the scene background


To start with, we will need a C# script.

Perform the following steps:

  1. First, search the Assets/Scripts folder and right-click on it.

  2. Then, click on Create and select C# Script.

  3. Now, name this SceneBackground.

  4. Finally, double-click on the SceneBackground file to open it.

The SceneBackground file will hold four sprites. Each of these sprites will have their own movement speed and movement distance (speed being how fast they move and distance is how far forward and backward they can move).

Add the following code to the SceneBackground file before the Start function:

    // Struct to hold data for Background Element
    [System.Serializable]
    public struct BackgroundElement
    {
      public Sprite BackgroundSprite;
      public float MovementSpeed;
      public float MovementDistance; 
      public Vector3 SpriteLocation;
      public Vector3 SpriteScale;

      [System.NonSerialized]
      public Vector3 ObjectStartLocation;
      [System.NonSerialized]
      public...