Game Development Reference
In-Depth Information
1. using UnityEngine;
2. using System.Collections; 3.
4. [RequireComponent(typeof(PhysicsCharacter))]
5. public class TopViewControl : MonoBehaviour { 6.
7.
//Reference to the physics character
8.
PhysicsCharacter pc;
9.
10.
void Start () {
11.
//Get the attached physics character
12.
pc = GetComponent<PhysicsCharacter>();
13.
}
14.
15.
void Update () {
16.
//Use arrows to control the movement
17.
if(Input.GetKey(KeyCode.RightArrow)){
18.
pc.StrafeRight();
19.
} else if(Input.GetKey(KeyCode.LeftArrow)){
20.
pc.StrafeLeft();
21.
}
22.
23.
if(Input.GetKey(KeyCode.UpArrow)){
24.
pc.WalkForward();
25.
} else if(Input.GetKey(KeyCode.DownArrow)){
26.
pc.WalkBackwards();
27.
}
28.
29.
}
30.}
Listing 73: A script to control physics character from a top view. Jumping is not enabled in this controller
Since we are developing a game in which the player has multiple lives, it is important to
save the cube that represents player as a prefab, which gives us the ability to destroy/regen-
Search WWH ::




Custom Search