Download Complete C# Game Programming Cookbook for Unity 3D 2nd Edition Jeff W. Murray PDF for All Chapters
Download Complete C# Game Programming Cookbook for Unity 3D 2nd Edition Jeff W. Murray PDF for All Chapters
Download Complete C# Game Programming Cookbook for Unity 3D 2nd Edition Jeff W. Murray PDF for All Chapters
com
https://textbookfull.com/product/c-game-programming-
cookbook-for-unity-3d-2nd-edition-jeff-w-murray/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/learning-c-programming-with-
unity-3d-alex-okita/
textboxfull.com
https://textbookfull.com/product/game-programming-in-c-
creating-3d-games-creating-3d-games-sanjay-madhav/
textboxfull.com
https://textbookfull.com/product/unity-game-development-cookbook-
essentials-for-every-game-1-converted-edition-paris-buttfield-addison/
textboxfull.com
3D Game Programming for Kids Create Interactive Worlds
with JavaScript 2nd Edition Chris Strom
https://textbookfull.com/product/3d-game-programming-for-kids-create-
interactive-worlds-with-javascript-2nd-edition-chris-strom/
textboxfull.com
https://textbookfull.com/product/beginning-game-ai-with-unity-
programming-artificial-intelligence-with-c-sebastiano-m-cossu/
textboxfull.com
https://textbookfull.com/product/developing-2d-games-with-unity-
independent-game-programming-with-c-1st-edition-jared-halpern/
textboxfull.com
https://textbookfull.com/product/developing-2d-games-with-unity-
independent-game-programming-with-c-1st-edition-jared-halpern-2/
textboxfull.com
https://textbookfull.com/product/3d-game-programming-for-kids-create-
interactive-worlds-with-javascript-1st-edition-chris-strom/
textboxfull.com
C# Game Programming
Cookbook for Unity 3D
C# Game Programming
Cookbook for Unity 3D
Second Edition
Jeff W. Murray
Second Edition published 2021
by CRC Press
6000 Broken Sound Parkway NW, Suite 300, Boca Raton, FL 33487-2742
and by CRC Press
2 Park Square, Milton Park, Abingdon, Oxon, OX14 4RN
First Edition published by CRC Press 2014
CRC Press is an imprint of Taylor & Francis Group, LLC
© 2021 Taylor & Francis Group, LLC
The right of Jeff W. Murray to be identified as author of this work has been asserted by
him/ in accordance with sections 77 and 78 of the Copyright, Designs and Patents Act
1988.
Reasonable efforts have been made to publish reliable data and information, but the
author and publisher cannot assume responsibility for the validity of all materials or the
consequences of their use. The authors and publishers have attempted to trace the copy-
right holders of all material reproduced in this publication and apologize to copyright
holders if permission to publish in this form has not been obtained. If any copyright
material has not been acknowledged please write and let us know so we may rectify in any
future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted,
reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other
means, now known or hereafter invented, including photocopying, microfilming, and
recording, or in any information storage or retrieval system, without written permission
from the publishers.
For permission to photocopy or use material electronically from this work, access www.
copyright.com or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood
Drive, Danvers, MA 01923, 978-750-8400. For works that are not available on CCC please
contact [email protected]
Trademark notice: Product or corporate names may be trademarks or registered trade-
marks and are used only for identification and explanation without intent to infringe.
ISBN: 978-0-367-32170-3 (hbk)
ISBN: 978-0-367-32164-2 (pbk)
ISBN: 978-0-429-31713-2 (ebk)
Typeset in Minion
by SPi Global, India
This book is dedicated to my
amazing wife, Tori, and to
my boys, Ethan and William.
Boys, be nice to the cat and
the cat will be nice to you!
Contents
Acknowledgments xiii
Introduction xv
Prerequisites xvii
vii
2. Making a 2D Infinite Runner Game 9
2.1 Anatomy of a Unity Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.2 Open Unity, Then the Example Project for This Chapter . . . . . . . . . . 10
2.2.1 A Few Notes on the Example Project . . . . . . . . . . . . . . . . . .12
2.2.2 Sprites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2.3 Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.3 Open the Main Game Scene . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.4 The Game Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.5 Making Platforms to Run On . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.6 Building the Player, RunMan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.6.1 Adding the RunMan Sprite . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.6.2 Adding Physics and Collisions to RunMan . . . . . . . . . . . . 23
2.6.3 Player Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.6.4 RunMan Sounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.6.5 Animating RunMan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.6.6 Scoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.7 The Game Loop and the Game Manager . . . . . . . . . . . . . . . . . . . . . . . 28
2.7.1 Game States . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.7.2 The Main Loop of RunMan_GameManager.cs . . . . . . . . . 29
2.7.3 Setting Up the RunMan_Game Manager
Component in the Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.8 The Demise of RunMan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.9 Adding the User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.9.1 Main Menu Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4. Player Structure 61
4.1 A Player Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
4.2 Dealing with Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
4.3 User Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
4.3.1 The UserData Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
4.3.2 The BaseUserManager Class . . . . . . . . . . . . . . . . . . . . . . . . . 66
4.4 The BasePlayerStatsController Class . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
4.5 Managing Players . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
viii Contents
5.3 Camera . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
5.3.1 Third-Person Camera . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
5.3.2 Top-Down Camera . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.4 Game Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.4.1 GlobalRaceManager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.4.2 RaceController . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.5 Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
5.5.1 Mouse Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
5.6 Level Loading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
5.7 ScriptableObjects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
5.7.1 ProfileScriptableObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
5.8 Spawning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
5.8.1 A Spawner Component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
5.8.2 Trigger Spawning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
5.8.3 Timed Spawning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
5.9 User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
5.9.1 CanvasManager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
5.9.2 ScreenandAudioFader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
5.9.3 MenuWithProfiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
5.10 Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
5.10.1 AlignToGround . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
5.10.2 AutomaticDestroyObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
5.10.3 AutoSpinObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
5.10.4 FaceCamera . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
5.10.5 LookAtCamera . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
5.10.6 PretendFriction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
5.10.7 TimerClass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
5.10.7.1 Modifying the Timer to Update
Automatically����������������������������������������������������100
5.10.8 WaypointsController . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
5.11 Weapons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Contents ix
9. Recipe: Sound and Audio 145
9.1 Audio Mixers and Mixing Audio in Unity . . . . . . . . . . . . . . . . . . . . . 145
9.1.1 Mixing Audio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
9.1.2 Exposing Mixer Properties to Modify Them with Scripts . . 146
9.1.3 Audio Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
9.2 The BaseSoundManager Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
9.3 Adding Sound to Weapons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
x Contents
14.4.5 Audio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
14.4.5.1 Vehicle Audio����������������������������������������������������259
14.4.5.2 Incidental Sounds����������������������������������������������259
14.4.6 User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
Index 283
Contents xi
Acknowledgments
Thanks to all of my family, friends and everyone who has helped me with my
books, games and projects over the years: Brian Robbins, Chris Hanney,
Technicat, Molegato, NoiseCrime, Quantum Sheep, Mickael Laszlo, Juanita
Leatham, CoolPowers, Dave Brake, Sigurdur Gunnarsson, Kevin Godoy R.,
Lister, Wim Wouters, Edy (VehiclePhysics), IdeaFella, Liam Twose, RafaEnd,
Lynxie, Alistair Murphy, McFunkypants, Dani Moss, Malcolm Evans, Vinh,
Scott Wilson, Jon Keon, Dunky, Huck Z, Paradise Decay, Kryten, Silverware
Games, Pete Patterson, Dr. Not Oculus VR, Say Mistage, Andy Hatch, Lydia, RT
Warner, GermanRifter VR, Sylvain Demers, Kenneth Seward Jr, Dancer (Space
Dad), Steve Fulton, Paul Bettner, Derek Scottishgeeks, Jonny Gorden, Edward
Atkin, Ottawa Pete, Sam W., Dylan Stout, Shane McCafferty, Will Goldstone,
Sanborn VR, Gary Riches, J. Dakota Powell, Mayonnaise Boy, Stephen Parkes,
Ram Kanda, Alex Bethke, Itzik Goldman, Joachim Ante, Robert Scoble, Tony
Walsh, Andreas ‘BOLL’ Aronsson, Cat, Darrel Plant, Mike Baker, Rimsy, Cassie,
Christopher Brown, Phil Nolan, Pixel Hat Studio, Marcus Valles, Trev, Karyl,
Tami Quiring, Nadeem Rasool, Dwayne Dibley, Liz and Pete Smyth, Isaac and
Aiden, David Helgason, VR Martin, James Gamble, Vasanth Mohan, Simona
Ioffe, Alexander Kondratskiy, Tim and Paul, The Oliver Twins, Jeevan Aurol,
Rick King, Aldis Sipolins, Ric Lumb, Craig Taylor, Rob Hewson, Dani Moss,
Jayenkai (JNK), Matthew Kirubakaran, Elliot Mitchell, Ethan and William,
Pablo Rojo, Paul Bettner, AdrellaDev, Gordon Little, Ryan Evans, Sasha Boersma,
Matt Browning at Perfect Prototype, Hermit, Dirty Rectangles and the whole
Ottawa game dev community.
xiii
I would also like to sincerely thank Anya Hastwell, Thivya Vasudevan and
the team at SPI Global, the whole team at Routledge/CRC Press/AK Peters,
including Randi Cohen, Jessica Vega and Rick Adams, for making this book a
reality.
Thank you for buying this book and for wanting to do something as cool as
to make games. I wish I could tell you how awesome it feels to know that someone
else is reading this right now. I cannot wait to see your games and I sincerely hope
this book helps you in your game making adventures. Have fun making games!
xiv Acknowledgments
Introduction
The overall goal of this book is to provide a library of C# code with which to
jumpstart your projects and to help you with the overall structure of your games.
Many development cookbooks focus on only providing snippets of code, but,
here, we take a different approach. What you are holding in your hands right now
(or on your screen) is a cookbook for game development that has a highly flexible
core framework designed to speed up development of just about any type of Unity
project.
You might think of the framework as a base soup and the scripting compo-
nents as ingredients. We can mix and match script components and we can share
the same core scripts in many of them. The framework takes care of the essentials
and we add a little extra code to pull it all together the way we want it to work.
The framework is optional, however – you can use a lot the components indi-
vidually. If you intend on using the components in this book for your own games,
the framework could either serve as a base to build your games on or simply as a
tutorial test bed for you to rip apart and see how it all works. Perhaps you can
develop a better framework or maybe you already have a solid framework in
place. If you do find a way to develop your own framework, I say do it. The key to
game development is to do what works for you and your game projects – what-
ever it takes to cross the finish line.
I hope it helps you to make your games and tell your stories. I also hope you
remember to try to have fun doing it!
xv
Prerequisites
You can get up and running with the required software for the grand total of zero
dollars. Everything you need can be downloaded free of charge with no catches.
All you need is:
C# programming knowledge.
This is not a book about learning how to program. You will need to know
some C# and there are several other books out there for that purpose, even if I
have tried to make the examples as simple as possible!
xvii
1 Making Games in a
Modular Way
1.1.1.1 Managers
Managers deal with overall management, in a similar way to how a Manager
would work in a workplace situation.
1.1.1.2 Controllers
Controllers deal with systems that the managers need to do their jobs. For exam-
ple, in the racing game example game for this book, we have race controller
scripts and a global race manager script. The race controller scripts are attached
to the players and track their positions on the track, waypoints, and other rele-
vant player-specific race information. The global race manager script talks to all
1
the race controller scripts attached to the players to determine who is winning
and when the race starts or finishes.
1. Direct referencing scripts via variables set in the editor by the Inspector
window.
The easiest way to have script Components talk to each other (that is, scripts
attached to GameObjects in the Scene as Components) is to have direct refer-
ences, in the form of public variables within your code. They can then be popu-
lated in the Inspector window of the Unity editor with a direct link to another
Component on another GameObject.
Above, this would call the function DoSomething() on any of the script
Components attached to the GameObject referenced by someGameObject.
3. Static variables.
The static variable type makes a variable accessible to other scripts without a
direct reference to the GameObject it is attached to. This is particularly useful
behavior where several different scripts may want to manipulate a variable to do
things like adding points to a score or set the number of lives of a player, and so on.
An example declaration of a static variable might be:
public static GameManager aManager;
1.1.1.4 Public Static
A public static variable exists everywhere and may be accessed by any other
script.
For example, imagine a player script which needs to tell the Game Manager
to increase the current score by one:
2. In any other script, we can now access this static variable and alter the
score as needed:
GameController.gameScore++;
When a player script is first created, it uses the value of uniqueNum for itself
and increases uniqueNum by one:
myUniqueNum = uniqueNum;
uniqueNum++;
The value of uniqueNum will be shared across all player scripts. The next
player to be spawned will run the same start up function, getting uniqueNum
again – only this time it has been increased by one, thanks to the player spawned
earlier. This player again gets its own unique number and increases the static
variable ready for the next one.
1.1.2 The Singleton
A singleton is a commonly used method for allowing access to an instance of a
class, accessible to all other scripts. This pattern is ideal for code that needs to
communicate with the entire game, such as a Game Manager.
instance = this;
}
}
1.1.3 Inheritance
Inheritance is a complex concept, which calls for some explanation here because
of its key role within the scripts provided by this book. Have a read through this
section but don’t worry if you don’t pick up inheritance right away. Once we get
to the programming it will probably become clearer.
Car–
–Wheels
–Engine
Car class.
Wheels function
Engine function
If we were building a game with lots of cars in it, having to rewrite the car class for
each type of car would be silly. A far more efficient method might be to write a base
class and populate it with virtual functions. When we need to create a car, rather
than use this base class, we build a new class, which inherits the base class. Because
our new class is inherited, it is optional whether we choose to override wheels or
engine functions to make them behave in ways specific to our new class. That is, we
can build ‘default’ functions into the base class and if we only need to use a default
behavior for an engine, our new class doesn’t need to override the engine function.
A base class might look something like this:
public class BaseCar : MonoBehaviour {
There are two key things to notice in the above script. One is the class declara-
tion itself and the fact that this class derives from MonoBehaviour. MonoBehaviour
is itself a class – the Unity documentation describes it as “the base class every
script derives from” – this MonoBehaviour class contains many engine-specific
functions and methods such as Start(), Update(), FixedUpdate(), and more. If our
script didn’t derive from MonoBehaviour it would not inherit those functions and
the engine wouldn’t automatically call functions like Update() for us to be able to
work with. Another point to note is that MonoBehaviour is a class that is built into
the engine and not something we can access to edit or change.
The second point to note is that our functions are both declared as virtual
functions. Both are public, both are virtual. Making virtual functions means that
the behavior in our base class may be overridden by any scripts that derive from it.
The behavior we define in this base class could be thought of as its default behav-
ior. We will cover overriding in full a little further on in this section.
The first thing you may notice is that the OctoCar class derives from BaseCar
rather than MonoBehaviour. This means that OctoCar inherits functions and meth-
ods belonging to our BaseCar script. As the functions described by BaseCar were
virtual, they may be overridden. For OctoCar, we override Wheels with the line:
public override void Wheels () {
Let’s take a look at what this script actually does: In this case, if we were to
call the Engine() function on OctoCar, it would do the same as the BaseCar class;
it would write “Vroom” to the console. It would do this because we have inherited
the function but have not overridden it, which means we keep that default behav-
ior. In OctoCar, however, we have overridden the Wheels() function. The BaseCar
behavior of Wheels would print “Four wheels” to the console but if we call
Wheels() on OctoCar, the overridden behavior will write “Eight wheels,” instead.
Inheritance plays a huge part in how our core game framework is structured.
The idea is that we have basic object types and specific elaborated versions of
these objects inheriting the base methods, properties, and functions. By building
our games in this manner, the communication between the different game com-
ponents (such as game control scripts, weapon scripts, projectile controllers, etc.)
becomes universal without having to write out the same function declarations
over and over again for different variations of script. For the core framework, our
main goal is to make it as flexible and extensible as possible and this would be a
much more difficult if we were unable to use inheritance.
1.1.4 Coroutines
Unity lets you run a function known as a coroutine, outside of the regular built
in functions like Update, FixedUpdate, LateUpdate, and so on. A coroutine is
self-contained code that will just go off and do its own thing once you have told
it to run. As it is running on its own, you can do some cool stuff like pause it for
a set amount of time and then have it start again, and coroutines are ideally suited
to time-based actions like fade effects or animations.
Here is an example of a coroutine (this example code comes from the Unity
engine documentation):
IEnumerator Fade()
{
for (float ft = 1f; ft >= 0; ft -= 0.1f)
{
Color c = renderer.material.color;
c.a = ft;
renderer.material.color = c;
yield return null;
}
}
Do not be alarmed by this odd code above! All it does is tell the engine that,
at this point, the coroutine is ready to end this update and go on to the next one.
You need this in your code, but don’t worry too much about why at this stage.
I will go into some more detail below, but for now let us continue by looking at
how you would start this coroutine running:
StartCoroutine("Fade");
You can think of IEnumerator like a cursor making its way through your
code. When the cursor hits a yield statement, that tells the engine that this update
is done and to move the cursor on to the next block.
Another thing you can do with coroutines is to pause the code inline for a
certain amount of time, like this:
yield return new WaitForSeconds(1.0f);
Using WaitForSeconds(), you can quite literally pause the coroutine script
execution inline. For example:
IEnumerator DebugStuff()
{
Debug.Log("Start.");
yield return new WaitForSeconds(1.0f);
Debug.Log("Now, it’s one second later!");
Earlier in this section, I mentioned that the yield statement is used to tell
Unity the current update is done and to move on to the next. In the code above,
rather than just telling Unity to move on to the next bit of code, it tells Unity to
wait for the specified number of seconds first.
1.1.5 Namespaces
Namespaces compartmentalize chunks of code away from each other. You can
think of a namespace as a box to put your own scripts in, so that they can stay
separated from other code or code libraries. This helps to prevent possible
namespace MyNamespace
{
public class MyClass() : Monobehaviour
{
}
When you want to refer to the code from another class, you need to be either
wrapped in the same namespace or to have the using keyword at the top of the
script, like:
using MyNamespace;
Switch(currentGameState)
{
Case GameStates.GameLoaded:
GameLoaded();
Break;
Case GameStates.GameStarting:
GameStart();
Break;
Having code in each case statement can get unruly. To counter this, I like to
split all of the code out into individual functions. This keeps the code tidy, easier
to manage, and easier to debug when things do not go to plan.
Where scripts need to be initialized before they can be used, in this book we
always use a Boolean variable named didInit which gets set to true after initial-
ization. You can use didInit to make sure initialization has completed.
Many programmers frown on the idea of declaring temporary variables, but
I like to have _tempVEC and _tempTR variables available for whenever I need to
refer to a quick Vector3 or another Transform inline. Having these variables
already declared is just a little quicker than having to declare a new Vector3 each
time, or to make a new Transform variable.
This chapter is different from the rest of the book and a dramatic diversion from
what you may have seen in its first edition. Elsewhere in the text, I focus mainly on
the code behind the games. This chapter offers up a step by step tutorial to using the
framework to make a 2D infinite runner game. The goal of this chapter is to dem-
onstrate two things: 1) How quickly you can turn around a game when you have a
framework in place that takes care of a lot of the repetitive tasks. 2) The basics of
how this books framework fits together to give you some background knowledge
before we get down into nitty gritty of the framework code in Chapter 3.
This infinite runner (Figure 2.1) has a character that can move left, right, and
jump. Platforms are spawned off-screen and moved to the left to create the illu-
sion of movement.
I have already set up animations and imported the required graphics into the
example project to get things going quickly. As the focus of this book is more
toward code, project structure, and programming, I want to avoid using up too
many pages on making graphics or on Unity editor-specifics. The Unity docu-
mentation features plenty of content on this.
Players jump and move to stay on the platforms if possible, with the score incre-
mented at timed intervals. If the player falls off the bottom of the screen, the game ends.
To accomplish this, we will need:
3. Platforms (auto moving to the left) and a method to spawn platforms off
screen
9
Figure 2.1 In the Infinite Runner example game, players jump and run to try to stay on the
platforms for as long as possible.
4. A Game Manager script to keep track of game state and deal with scor-
ing and so forth
6. An animated character
With just the framework and assets, by the end of this chapter, we will have
a working game.
For three days after the passionate scene that has been described,
Rupert saw no more of Mea. When he asked about her, not without
anxiety, Bakhita, who had taken her place as his nurse, informed him
that she had gone to a distant part of the oasis to inquire about her
crops, and to settle a dispute between two families as to some land.
For some reasons he wished that she would come back again, since
during those days Bakhita was very short with him; indeed, the word
“harsh” would scarcely have exaggerated her attitude.
“I know you are angry with me,” he said at last, “but you who are
wise and acquainted with our law, will understand.”
“I understand that you are a fool, Rupert Bey, like many of you
white men who think yourselves so good and clever. I wish you had
never come to Tama, for now my niece will go unmarried, and the
ancient race must die.”
“It is not my fault,” he answered humbly, “it is yours, Bakhita, who
would accompany me somewhat against my will, and thus have
brought ruin upon everybody.”
“Nay,” she answered crossly, “it was yours, who spied upon us in
the sanctuary at Abu-Simbel, and thus caused the libation to be
poured amiss. From that moment Tama became your slave, and the
god grew jealous and brought evil upon us all, especially upon you,
Rupert Bey.”
He laughed a little and said:
“You don’t really believe all that, do you, Bakhita? Those old gods
have been dead for many an age.”
“I am not sure what I believe,” she answered, “but departed faiths
still haunt the blood of those whose fathers held them, and the
ancient gods live on in other forms. To-day none worship ours, save
I, for Mea turned from him to you, and the people have forgotten
long ago. Well, I was sure that ill-luck would come, and so it has.
Still, I do not blame you, Rupert Bey, who are brave and honest, and
have dealt well by her whom you might have betrayed and left. Nor,”
she added, with a curious burst of conviction, “nor am I sure that
things will go so ill after all. You said to us one day that the spirit is
greater than the flesh, and that those who follow the spirit win at
last. Though you seem such a fool, perhaps you are right, Rupert
Bey. I think so at times, for, look you, I also have put aside the flesh
and followed the spirit all my life, and learned much, for do they not
call me wise and foresighted? Only,” she added reflectively, “perhaps
I have followed the false spirit, and you follow the true. Perhaps the
old gods are really dead at last, and new ones rule the world. But if
so, in the Soudan they are devils. Meanwhile, Rupert Bey, deal
gently with the flower whose stalk you have broken in your clumsy
hand, lest the air should soon lack its fragrance.”
On the third day Mea reappeared, looking rather pale and red-
eyed, but outwardly, at any rate, in a cheerful mood. Not one word
did she say then or afterwards to Rupert about their great argument
as to the moralities of the East and West. For whether she had been
visiting her crops, or perchance lying weeping on her bed, at least it
would seem that she had conquered herself, and was determined to
adapt her life to the conditions upon which they had tacitly agreed.
By now it was certain that his sight would be restored to Rupert, and
this joyful fact worked wonders for them both. For instance,
mounted on a quiet mule, which a servant led, whilst others ran
before, behind, and around him, and Mea herself rode at his side,
she conducted him about the oasis that was her heritage.
It was a large place, thirty miles or more in length by perhaps
fifteen in breadth, which would have supported a great population,
as once it must have done, for its soil, washed down from the
mountain-sides, was of a marvellous fertility and very well-watered.
The local methods of cultivation, however, were primitive, and as the
trade with outside people was very small, its inhabitants had no
incentive to grow more than they could consume.
“If I had the management of this oasis for ten years,” said Rupert
to Mea, after he had inspected most of it, “I would make you the
richest woman in the Soudan.”
“Then stay and make me so,” she answered, smiling. But he felt
that it was not the riches which she desired.
What interested him even more were the ruins of the great temple
which had evidently been devoted to the worship of Ra—that is, the
Sun as the robe and symbol of Divinity. It was of a late period,
Ptolemaic indeed, and not of the best workmanship, and there were
various passages in the inscriptions which seemed to suggest that it
was founded by some Egyptian prince of the thirtieth dynasty, who
fled hither after the reconquest of Egypt by the Persians. It
appeared that his descendants for many generations kept a kind of
royal state in this far-off oasis where nobody thought it worth while
to attack them. Indeed, on the sarcophagus of one of them who
died as late as the reign of Theodosius four centuries after Christ,
was an inscription pompously describing the deceased as “Beloved
of Ra, King of Tama and of Upper and Lower Egypt.”
The most impressive part of this temple, indeed, was the
mausoleum of the rulers of the oasis who had called themselves
kings. Probably because they could not afford to make for
themselves great separate tombs after the fashion of those in the
Valley of Kings at Thebes, they hollowed in the rock beneath the
temple a vast crypt, from which opened outside chambers like to
those of the Serapeum, the burying-place of the sacred bulls of
Memphis. At the head of this crypt stood a huge and solemn statue
of Osiris in his mummy wrappings, but wearing the crown and
feathers of Amen-Ra, and at its entrance was a great underground
pool or cistern of water, across which the bodies of the dead were
ferried, in imitation, doubtless, of the last journey across the Nile.
Certain of the side-chambers were bricked up, but others were
either never closed, or had been opened, and there in their
sarcophagi lay the dead.
In a past age some of the granite coverings and coffin-lids had
been removed, but the mummies remained inviolate, even their
golden ornaments were not disturbed. Those of one young queen,
or rather chieftainess, who had died a few years before the birth of
Christ were indeed of remarkable beauty and great value,
comprising a crown of gold filagree and enamelled flowers of
marvellous workmanship, inlaid pectoral and bracelets and a sceptre
of gold surmounted by a crystal symbol of the sun. Mea took them
from the body and arrayed herself in them and stood before Rupert
a queen of Egypt, as once he had seen her stand in the sanctuary at
Abu-Simbel. Very wonderful she looked thus with the lamp-light
shining upon her in that awesome, silent place.
“What are you doing?” he asked, for notwithstanding the bizarre
beauty of her decorations, it jarred upon him to see her ornamented
with these insignia of death.
“I try them on, Rupert Bey,” she answered. “As we cannot make
such things now I will borrow them from the lady, my long-ago
grandmother, to be buried in. Come here; I show you my tomb.”
Then she led the way past certain built-up chambers in which, she
informed him, her immediate predecessors lay uncoffined, to a
recess where was a magnificent sarcophagus of alabaster. It was
graved about with the usual texts from the Book of the Dead, but
had several peculiarities. Thus in its great interior were places for
two bodies with a little ridge of alabaster left to separate them. It
was quite empty, the massive lid which stood by its side never
having been put on. Also the spaces for the name, or names, of its
occupants were left blank, showing that those for whom it was
prepared rested elsewhere.
“Where are they?” asked Rupert, as with the help of Mea and his
crutch he scrambled down from the pediment of the tomb.
“Don’t know,” she answered, “perhaps die somewhere else, or
killed by enemy; perhaps quarrel, and no wish to be buried together.
I take their house when my time comes; just fit me.”
“Then you mean your husband to lie there too?” blurted out
Rupert, without thinking.
Holding the lamp in her hand she turned and looked at him with
steady eyes.
“Understand, Rupert Bey,” she said, “I have no husband, never—
never. All day I work alone, when night come I sleep alone. Then my
people build up this place—all, all, for I the last and nobody ever
come in here any more. Yes, build it up with stone of the temple and
make it solid like the mountain, for I wish to sleep long and quiet.”
Such were the oasis Tama and its antiquities. Of its people there is
little to say, save that they were grave in demeanour, rather light in
colour and handsome in appearance, especially the women, looking
much as the last descendants of an ancient and high-bred race
might be expected to look. The men, as we have seen, were brave
enough in war, suspicious and exclusive also, but indolent at home,
doing no more work than was necessary, and for the most part
lacking the energy to trade. Their customs as regards marriage and
other matters were those common to Nubia and the Soudan, but
although they talked of Allah they were not Mahommedans, and if
they worshipped anything, it was God as symbolised by the sun.
Indeed this was all that remained of their ancient faith, with the
exception of certain feasts and days of mourning, whereof they had
long forgotten the origin. Only a few of the old women before a
marriage or a burial, or any other event of importance, would
occasionally creep down to the vault and pour a libation to the
statue of Osiris that wore the crown and feathers of Amen-Ra, as, in
an hour of danger, Bakhita had made Mea do at Abu-Simbel.
This survival was interesting, but Rupert was never able to
discover whether it had descended from the ancient days, or
whether they had learnt the practice from the sculptures on the
temple and the paintings in the vault, which showed the departed
rulers and their wives and attendants pouring such libations before
this very statue. At least, of the old religion nothing else remained,
nor could anyone in Tama read the hieroglyphics. It was her desire
to acquire this and other learning, and to become acquainted with
those men and the wonderful outside world, whereof rumours had
reached her in her isolated solitude, that had caused Mea to disguise
herself and spend two years at the school at Luxor. Here, although,
as she found to her disappointment, they did not teach
hieroglyphics, she had accumulated a considerable quantity of
miscellaneous knowledge of men and things, including a superficial
acquaintance with the English tongue, in which she loved to talk.
Now she insisted upon continuing her education under Rupert’s
guidance, and as they had only one book, the instruction took the
form of lectures upon history, literature, art, and everything else
under the sun with which he had the slightest acquaintance. It was
a strange sight to see them in one of the big rooms of her house,
Mea seated at a little table and Rupert limping to and fro upon his
crutch, and holding forth on all things, human and Divine, such as
Egyptology—of which he really knew something; modern political
history, especially that of Africa, and religion. Indeed, the last played
a large part in their studies, for as it happened among the few
belongings that were saved from the saddle-bags of his camel was
Rupert’s Bible, that same skin-bound volume which had excited
Edith’s wonder and interest. Therefore it was out of this Bible that he
made her read to him, with the result that she learned from it more
than the letter. As he intended that she should, soon she began to
appreciate the spirit also, and in its light to understand much that
had puzzled her in Rupert’s conduct towards herself and others. But
the knowledge did not teach her to love him less, only perhaps she
honoured him the more.
So the weeks passed on, and strange as were the conditions of his
life, not altogether unhappily for Rupert. As yet it was impossible for
him to leave the oasis for the reasons that have been given, and
sometimes with a sudden sense of shame, he awoke to the fact that
this detention was no longer the agony to him that it had been at
first; that now indeed he could endure it with patience. Of course
the truth was that we are all of us very much the creatures of our
immediate surroundings, and that the atmosphere of this peaceful
desert home had crept into his being, bringing with it rest, if not
content. He had suffered so much in mind and body, and now he
was not called upon to suffer. So skilful was she in her dealings with
him, so well did she veil her heart in its wrappings of courtesy and
friendship, that he ceased even, or at any rate to a great extent, to
be anxious about Mea.
He tried to forget that passionate scene, and when he did think of
it his modesty prompted him to believe that it really meant nothing.
Eastern women were, he knew, very impulsive, also very changeful.
Probably what had moved her, although at the time she did not
know it, was not devotion to a shattered hulk of a man like himself,
but as she had said at the beginning, pity for his sad state of which
indirectly she was the cause.
Al least he hoped that it was so, and what we hope earnestly in
time we may come to believe. So that trouble was smoothed away,
or at any rate remained in abeyance.
For the rest those palms and mountain-tops, those bubbling
waters and green fields, that solemn, ruined temple and those
towering pylons, were better than the parks and streets of London,
or that hateful habitation in Grosvenor Square where Lord Devene
leant against his haunted marble mantel-piece and mocked. Indeed,
had it not been for Edith and his mother, Rupert would, he felt, be
content, now that his career had gone, to renounce the world and
live in Tama all his days. But these two—the wife who must think
herself a widow, and the mother who believed herself sonless, he
longed ceaselessly to see again. For their sakes, day by day he
watched for an opportunity of escape.
At length it came.
“Rupert Bey,” said Mea quietly to him one morning in Arabic as
they sat down to their usual lesson, “I have good news for you. By
this time to-morrow you may be gone from here,” and whilst
pretending to look down at the parchment upon which she was
writing with a reed pen, as her forefathers might have done twenty
centuries before—for paper was scarce with them—she watched his
face from beneath her long lashes.
The intelligence stunned him a little, preventing—perhaps
fortunately—any outbreak of exuberant joy. Indeed, he only
answered in the words of the Arabic proverb:
“After calm, storm; after peace, war,” and the reply seemed to
satisfy Mea, although she knew that this proverb had an end to it
“after death, paradise—or hell.”
“How, Mea?” he asked presently.
“A big caravan, too strong to be attacked, is going to cross the
Nile above Wady-Halfa and pass through the Nubian desert to the
shores of the Red Sea beyond the country that is held by Osman
Digna. Its chief, who is known to our people, and a true man, makes
the pilgrimage to Mecca. I have sent messengers to him. He is
willing that you should accompany him, only you must not say who
you are, and if they meet any white men you must promise not to
talk to them. Otherwise, you may bring him into trouble for the
befriending of a Christian.”
“I will promise that,” answered Rupert.
“Good! Then you leave here to-morrow morning at the dawn.
Now, let us go on with the lesson; it is my last.”
That lesson proved a very desultory performance; indeed, it
consisted chiefly of a compilation by Rupert of lists of books, which
he instructed Mea she was to send to Egypt to buy, as soon as there
was an opportunity, in order that she might continue her education
by herself. But Mea seemed to have lost all interest in the future
improvement of her mind.
What was the good of learning, she asked, if there was nobody to
talk to of what she had learned? Bakhita did not care for these
things, and the others had never heard of them.
Still she took the lists and said she would send for the books when
she could, that was, after the country grew quiet.
The rest of that miserable day went by somehow. There were
meals to eat as usual; also Rupert’s dromedary had to be got up,
and a store of food made ready for his journey. Mea wanted him to
take money, of which she had a certain amount hidden away—
several thousand pounds indeed—the products of her share of sales
of horses and corn which the tribe occasionally effected with
travelling merchants, who bought from them cheap and sold to the
Egyptian Government, or others, dear. But this he would not touch,
nor did he need to do so, for in his clothes when he was captured
were sewn about a hundred pounds, some in gold and some in
bank-notes, which he thought would be sufficient to take him to
England.
It was night. All was prepared. Rupert had said his farewells to the
emirs and chief men, who seemed very sorry that he was going.
Mea had vanished somewhere, and he did not know whether he
would see her again before he started at the dawn. The moon shone
brightly, and accompanied by the native dog that had led him when
he was blind, and having become attached to him, scenting
separation with the strange instinct of its race, refused to leave his
side that day, Rupert took his crutch and walked through the pylon
of the temple, partly in the hope that he might meet Mea, and partly
to see it once more at the time of full moon, when its ruin looked
most beautiful.
Through the hypostyle hall he went where owls flitted among the
great columns, till he came to the entrance of the vast crypt, a broad
rock-slope, down which in old days the sarcophagi were dragged.
Here he stopped, seating himself upon the head of a fallen statue,
and fell into a reverie, from which he was roused by the fidgeting
and low growlings of the dog, that ran down the slope and returned
again as though he wished to call his attention to something below.
At length his curiosity was excited, and led by the dog, Rupert
descended the long slope at the foot of which lay the underground
pool of water. Before he reached its end he saw a light, and limping
on quietly, perceived by its rays Bakhita and Mea, the former
bending over the pool, and the latter wrapped in a dark cloak,
seated native fashion at its edge. Guessing that the old gipsy was
celebrating another of her ancient ceremonies, he motioned the dog
to heel, stood still and watched.
Presently he saw her thrust out from the side of the pool a boat
about as large as that which boys sail upon the waters of the
London parks. It was built upon the model of the ancient Egyptian
funerary barges with a half deck forward, upon which lay something
that looked like a little mummy. Also, it had a single sail set. Bakhita
gave it a strong push, so that it floated out into the middle of the
pool, which was of the size of a large pond where, the momentum
being exhausted, it lay idly. Now the old woman stretched out a
wand she held and uttered a kind of invocation, which, so far as he
could hear and understand it, ran:
“Boat, boat, thou that bearest what was his, do my bidding. Sail
north, sail south, sail east, sail west, sail where his feet shall turn,
and where his feet shall bide, there stay. Boat, boat, let his Double
set thy sail. Boat, boat, let his Spirit breathe into thy sail. Boat, boat,
in the name of Ra, lord of life, in the name of Osiris, lord of death, I
bid thee bring that which was his, to north, south, east, or west,
where he shall bide at last. Boat, boat, obey.” *
* The Double and the Spirit here mentioned were doubtless those
constituent parts of the human entity which were known
respectively to the old Egyptians as the Ka (the Double), and the
Khu (the Soul itself). Of these, some traditional knowledge might
very well have descended to Bakhita.
She ceased and watched a little lamp which burnt upon the prow
of the boat, in front of the object that looked like a toy mummy. Mea
also rose and watched, while out of the darkness Rupert and the
dog watched too. For a little while the boat remained still, then one
of the numerous draughts that blew about these caverns seemed to
catch its sail, and slowly it drew away across the water.
“It goes west,” whispered Mea.
“Aye,” answered Bakhita, “west as he does. But will it bide in the
west?”
“I pray not,” answered Mea, “since ever from of old the west has
been the land of death, and therefore to the west of these waters lie
the sepulchres, and where the sun sets beyond the west bank of the
Nile, there for thousands of years our people laid their dead. Nay,
boat, tarry not in the west where Osiris rules, the cold and sorrowful
west. Return, return to the House of Ra, and in his light abide.”
Thus she murmured on, like one who makes a song to herself in
the Eastern fashion, all the while intently watching the little lamp
that showed the position of the boat. Having reached the western
edge of the pool, it seemed inclined to remain there, whereon Mea,
turning to Bakhita, began to scold her, asking her why she had
brought her there to see this childish play, and whether she thought
that she, Mea, who had been educated at Luxor and received many
lessons from the Bey, believed in her silly magic, or that a toy boat,
even though it did carry a man’s foot made up like a mummy, could
possibly tell whither he would wander.
“If the boat sails right, then you will believe; if it sails wrong, then
you will not believe. That I expected, and it is best,” answered
Bakhita drily, and at that moment something happened to the little
lamp that stood before the mummy foot, for suddenly it went out.
Now Mea grew positively angry, and spoke sharp words to Bakhita
as to her methods of divination and the benighted and primitive
condition of her intelligence in general.
“Were I to accept the augury of your boat,” she said, “I must be
sure not only that he will stay in the west, but that he will die there,
for look, the light is out.”
“Other things die beside men’s bodies,” answered Bakhita, in her
brief fashion; “their hopes, or beliefs, or perhaps their good luck—
who can say?”
As she spoke, suddenly out from the darkness of the pool into the
ring of light cast by the lamp which Bakhita bore, that fairy boat
came gliding. The gust of wind blowing down the western
sepulchres beyond the pool, which extinguished its lamp, had also
caught its sail and brought it back, half filled with water shipped in
turning; brought it back swiftly, but sailing straight to where Mea
knelt upon the edge of the pool. She saw it, and with a little cry of
joy, bent herself over the water, and stretching out her rounded
arms, caught the boat just before it sank, and hugged it to her
breast.
“Put the thing down,” said Bakhita. “You don’t believe in it, and it
is wet and will spoil your robe. Nay, the Bey’s foot is mine, not yours.
I brought it from the Wells.”
Then they began to quarrel over this poor mummied relic of which
Rupert thought that he had seen the last many a day before, while
he took an opportunity to beat his retreat. Bakhita and her ancient
spells were, as usual, interesting, though when they involved a lost
fragment of himself they became somewhat gruesome. But in such
things he had no belief whatsoever; they only attracted him as
historical, or rather as spiritual survivals. What moved him about the
matter was Mea’s part in it, revealing, as it did, that her interest in
his future had in no way abated. Indeed, he felt that it would be
long before he was able to forget the touching sight of this wayward
and beautiful girl, this desert-bred daughter of kings, snatching the
sinking boat and its grizzly burden from the water and pressing them
to her breast as though they were a living child. Meanwhile, the
accident that he had seen it did not make this farewell less difficult.
When at length he reached the house—for amongst the fallen
stones of the temple his progress with a crutch was slow—Rupert sat
down upon its steps, feeling sure that Mea would wish to see him,
and that it would be well to get that parting over. Presently the
mongrel at his side began to bark, and next minute he saw her
walking slowly up the path towards him, her cloak open and the
breast of her robe still wet where she had pressed the dripping boat
against it. He struggled from the step to meet her.
“Sit, Rupert Bey,” she said; “sit. Why trouble you to rise for me?”
“I cannot sit while you stand,” he answered.
“Then I sit also, on the other side of the dog. He look like the god
on the wall, does he not, what you call him—Anubis, brother of
Osiris? No, don’t growl at me, Anubis; I no hurt your master, you
nasty little god of the dead.”
“Where have you been, and why is your dress wet?” asked Rupert.
“Ask Anubis here, he wise, knows as much as his master. I been to
the burying-place and lean over holy water to look if I grow more
ugly than usual.”
“Stuff!” answered Rupert.
“You no believe me? Well, then, perhaps I thirsty and drink water.
Much weep make me thirsty. No believe still? Then perhaps I look in
water and see pictures there.”
“What pictures can you see in that dark place?”
“Oh, plenty, dark no matter. See things inside, like you when you
blind. I tell you what I see; I see you come back here, and so I
weep no more. I—I—happy. Make that dog go the other side, he
want to bite me now, he jealous because you look at me, not him.”
Accordingly the protesting Anubis was rearranged, and continued
his snarlings and grumblings from a safer distance.
“Some more of old Bakhita’s nonsense, I suppose,” said Rupert. “I
thought that you had given up believing in her myths and omens.”
“What mean myths and omens? No matter; Bakhita old fool, gods
old stones, believe in none of them. You say it, so all right. Believe in
you, and me—inside, what my heart tell me. My heart tell me you
come back. That why I happy.”
“Then I am afraid, Mea, that your heart knows more than I do.”
“Yes,” she answered, “think more; feel more, so know more. That
all right; what do you expect?” Then suddenly dropping her jerky
and peculiar English, Mea addressed him in her solemn and native
Arabic. “Hark you, Rupert, guest of my home, guest of my heart,
preserver of my body, who shed your blood for me. You think me
foolish, one who tries to warm her hands at the fires of the marsh,
one who plucks flowers that fade, and believes them immortal stars
fallen to deck her breast and hair. Yet she finds warmth in the marsh
fire, and in the dead flower’s heart a star. I believe that you will
come back, why or how it matters not, but to make sure you shall
swear an oath to me, you shall swear it by the name of your Jesus,
for then it will not be broke.”
“What oath?” asked Rupert anxiously.
“This: Sometimes lamps go out, and where we thought light was
there is great blackness. Sometimes hopes fail, and death stands
where life should have been. This may chance to you, Rupert Bey,
yonder in the cold, western land of the setting sun.”
“Do you mean that I shall find my wife dead?” he asked, with a
quiver in his voice. “Is that the picture you saw in your pool?”
“Nay; I saw it not; I do not know. I think she lives and is well. But
there are other sorts of death. Faith can die, hope can die, love can
die. I tell you I know not, I know nothing; I have no magic; I believe
in no divination. I only believe in what my heart tells me, and
perchance it tells me wrong. Still I ask you to swear this. If things
should so befall that there is nothing more to keep you in the West,
if you should need to find new faith, new hope, new love, then that
you will come back to Tama and to me. Swear it now by the name of
your God, Jesus; so I may be sure that you will keep the oath.”
“I do not swear by that name,” he answered. “Moreover why
should I swear at all?”
“For my sake, Rupert Bey, you will. Hear me and decide. I tell you
that if you do not come back, then I die. I do not ask to be your
wife, that does not matter to me, but I ask to see you day by day. If
I do not see you, then I die.”
“But, Mea,” he said, “it may be impossible. You know why.”
“If it is impossible, so be it, I die. Then it is better that I die.
Perhaps I kill myself, I do not know, at any rate I go away. I ask not
that you should swear to come, if it should make you break your
oath to others, only if there are no more oaths to keep. Now choose,
Rupert Bey. Give me life or give me death, as you desire. Make your
decree. I shall not be angry. Declare your will that your servant may
obey,” and she rose and stood before him with bent head and hands
humbly crossed upon her breast.
He looked at her. There could be no doubt she was in earnest.
Mea meant what she said, and she said that if he did not gratify this
strange wish of hers, and refused to give her any hope of his return,
she would die, or at least so he understood her; and was certain
that if she had the hope, she would not die and bring her blood
upon his head. Rupert looked at her again, standing there in the
moonlight like some perfect statue of humility, and his spirit melted
within him, a blush of shame spread itself over his scarred and
rugged features, shame that this loyal-hearted and most honoured
woman should thus lay her soul naked before him, saying that it
must starve if he would not feed it with the crumb of comfort that it
desired. Then he hesitated no longer.
“Mea,” he said, in the kind and pleasant voice that was perhaps
his greatest charm—“Mea, my law says: ‘Swear not at all’; I read it
to you the other day. Now, Mea, will my word do instead?”
“My lord’s word is as other men’s oaths,” she answered, lifting her
humble eyes a little.
Then he bent forward, resting on his knee, not as an act of
adoration, but because it was difficult to him to rise without
assistance, and stretching out his hand, took her crossed hands from
her breast, and bowing himself, pressed them against his forehead,
thus—as she, an Eastern, knew well—prostrating himself before her,
making the ancient obeisance that a man can only make with
honour to his liege sovereign, or to one who has conquered him.
“My lady Tama,” he went on, “after one other my life is yours, for
you gave it back to me, and after her and my mother there lives no
woman whom I honour half so much as you, my lady and my friend.
Therefore, Mea, since you wish it, and think that it would make you
happier, should I perchance be left alone—which God forbid!—I
promise you that I will come to you and spend my life with you until
you weary of me—not as a husband, which you say you do not
desire, which also might be impossible, but as a brother and a
friend. Is that what you wish me to say?” and he loosed her hand,
bowed to her once more in the Eastern fashion, with his own
outstretched, so that his fingers just touched her feet, and raised
himself to the step again.
“Oh!” she answered, in deep and thrilling tones, “all, all! More, by
far, than I had hoped. Now I will not die; I will live! Yes, I will keep
my life like a jewel beyond price, because I shall know, even if you
do not come, that you may come some time, and that if you never
come, yet you would have come if you could—that the marsh-light is
true fire, and that the flower will one day be a star. For soon or late
we shall meet again, Rupert Bey! Only, you should not have
prostrated yourself to me, who am all unworthy. Well, I will work, I
will learn, I will become worthy. A gift, my lord! Leave me that holy
book of yours, that I may study it and believe what you believe.”
He limped into the house and brought back the tattered old Bible
bound in buckskin.
“You couldn’t have asked for anything that I value more, Mea,” he
said, “for I have had that book since I was a child, and for that
reason I am very glad to give it to you. Only read it for its own sake
—not for mine—and believe for Truth’s sake, not because it would
please me.”
“I hear and I obey,” she said, as she took the book and thrust it
into the bosom of her loose robe.
Then for a moment they stood facing each other in silence, till at
length, perhaps because she was unable to speak, she lifted her
hands, held them over him as though in blessing, then turned and
glided away into the shadows of the night.
He did not see her any more.
CHAPTER XVI.
MEANWHILE
It was the last day of the old year when, had there been anyone
to take interest in her proceedings among so many finer vessels
going to or returning from their business on the great waters, a
black and dirty tramp steamer, whose trade it was to carry coals to
the East, might have been seen creeping up the Thames with the
tide. A light but greasy fog hung over the face of the river, making
navigation difficult, and blurring the outlines of the buildings on its
bank, and through it the sound of the church bells—for it was
Sunday—floated heavily, as though their clappers had been muffled
in honour of the decease of one of the great ones of the earth.
In his cabin—for after the suns of the Soudan the winter wind was
too cold to face—sat Rupert Ullershaw, dressed in a mustard-
coloured suit of reach-me-downs, somewhat too small for him, and
of a peculiarly hideous cut and pattern, which he had purchased
from a sailor. Physically he was in good health, but his mental
condition may best be described as one of nervous irritability born of
weeks and months of suspense. What news awaited him on his
arrival home, he wondered, and how would he, a discredited and
mutilated cripple, be received?
That he was discredited he knew already, for he had found an old
paper on board the ship, in which, on looking at it, his own name
had leapt to his eye. Someone had asked a question in Parliament
concerning him and his mission—why it had been sent, what were
the facts of the rumours of its annihilation, whether it was true that
this disaster had been brought about through the envoy, Lieutenant-
Colonel Ullershaw, C.B., having mixed himself up in tribal quarrels
over a native woman, and what was the pecuniary loss involved to
the country? Then followed the answer of the Secretary of State, the
man who had pressed him to go on the grounds of duty and
patriotism. It stated that Colonel Ullershaw had been despatched to
carry out certain confidential negotiations with a number of sheiks
on the borders of the Soudan. That according to the report received
from the Egyptian authorities, a native sergeant named Abdullah,
who accompanied him, had arrived at Cairo and informed them that
all the members of the mission, who were disguised as merchants,
had been attacked by a petty chief called Ibrahim and destroyed,
Abdullah alone escaping. That it appeared from this survivor’s
evidence that the attack was not political, but had its origin in
Colonel Ullershaw having unfortunately tried to protect two native
women who were travelling with him, one of whom, stated to be a
young person of some rank, was claimed by the sheik Ibrahim as a
wife. That the loss to the country, or rather to the Egyptian
Government, amounted to about two thousand pounds, of which
one thousand was in cash.
Arising out of this were other questions, evidently framed to annoy
the Government upon a small matter, such as: Was it true that
Colonel Ullershaw had been chosen over the heads of more suitable
persons, because his great family influence had been brought to
bear upon the War Office? To this the answer was that the deceased
officer’s record had been very distinguished, and he was chosen
because of his diplomatic experience, his knowledge of Arabic and
personal acquaintance with the sheiks, with whom it was necessary
to communicate: That, as the House would be aware, his family
influence as represented in that House, and, he might add, in
another place, was not likely to unduly influence Her Majesty’s
present advisers, of whom the gentlemen concerned were strong
and able opponents. (A laugh.)
The thirst for information not being yet appeased, an Irish
member asked whether it was true that a punitive expedition had
been sent to kill the chief whose wife Colonel Ullershaw had stolen—
(laughter); and whether the Government now regretted their choice
of Colonel Ullershaw as the head of this mission.
Answer: That such an expedition had been sent, but that it
appeared that Colonel Ullershaw and his party had made a very
gallant fight before they were overwhelmed, and that either he, or,
as was stated by some nomads, the lady, whom he had befriended,
with the help of her tribesmen had already killed the sheik Ibrahim
and most of his men, whose corpses had been seen by the nomads
hanging to some trees: That the Government admitted that their
choice had not been justified by events, but that he, the Secretary of
State, deprecated the casting of slurs upon very insufficient
information upon the memory of a brave and devoted servant of his
country—(hear, hear!)—whose mistakes, whatever they might have
been, seemed to have sprung from the exaggerated chivalry of his
nature. (A laugh.)
Another Irish member: Was it true that Colonel Ullershaw had
been married on the day he left England to enter upon this mission?
The Speaker: “Order, order. This House has nothing to do with the
domestic concerns of the late Colonel Ullershaw.”
The Honourable member apologised for his question, remarking
that his excuse for it must be that the country, or Egypt, had to pay
in lives and money for the domestic entanglements of Colonel
Ullershaw, in which he became involved among the desert sands.
(Much laughter and cries of order.) He wished to ask the Right
Honourable gentleman whether he was sure that the gallant Colonel
—(more laughter)—was really dead?
The Secretary of War: “I fear there is no doubt upon that point.”
The subject then dropped.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com