Setting up the player starting position
Every time our game starts, we should reset all its conditions to the same state. We already mentioned that resetting the starting position of the Player game object would be a good start. Positions in the 3D world in Unity are described using Vector3 struct. Go ahead and type Vector3 in the Scripting Reference for a better understanding. This is complex stuff, so don't worry if you can't get it. All you need to know now is that Vector3 is made up of three floats describing x, y, and z positions in the space.
Let's go forward and perform some code changes to set up the Player position. In PlayerController, we will do the following:
- Add a private
Vector3type variable and call itstartingPositioninPlayerController. - Assign the
startingPositionvalue taken from thePlayergame object world space position in theAwakemethod. This way, we will always store the initial position of thePlayergame object just after Unity starts executing the game. - Rename the...