Game Development Reference
In-Depth Information
relocationPoint = Vector3(0, 9, 18);
RelocatePlayer();
}
else if(Input.GetKeyDown(KeyCode.Alpha2)) {
relocationPoint = Vector3(0, 9, 33.5);
RelocatePlayer();
}
}
function RelocatePlayer(){
if (player != null) {
player.transform.position = relocationPoint;
player.gameObject.GetComponent(GoRagdoll).ExitRagdoll();
}
}
This code breaks down as follows:
(1) private var relocationPoint : Vector3;
1.
Declare a private variable relocationPoint of type Vector3.
(2) CheckInput();
2.
Call the CheckInput() function from the Update() function. Now you can
easily see that you are checking for user input each frame.
(3) function CheckInput () {
3.
Create a new CheckInput() function and move the code that checked the
player's input from the Update() function here.
(4) relocationPoint = Vector3(0, 9, 18);
and
relocationPoint = Vector3(0, 9, 33.5);
4.
Assign the new position associated with this key to the relocationPoint
variable.
(5) RelocatePlayer();
5.
Call the RelocatePlayer() function.
(6) function RelocatePlayer(){
6.
Create the RelocatePlayer() function . . .
(7) player.transform.position = relocationPoint;
7.
which begins with assigning the value of the Vector3 in the relocationPoint
variable as the new position of the player character.
Search WWH ::




Custom Search