Game Development Reference
In-Depth Information
1. using UnityEngine;
2. using System.Collections; 3.
4. public class BallRoller : MonoBehaviour { 5.
6.
//Movement speed on x and z axes
7.
public float moveSpeed = 5;
8.
9.
//Rolling speed of the ball
10.
public float rollSpeed = 360;
11.
12.
void Start () { 13.
14.
}
15.
16.
void Update () {
17.
//Move along global x axis and roll around global z axis
18.
if(Input.GetKey(KeyCode.UpArrow)){
19.
transform.Translate(0, 0,
20.
moveSpeed
*
Time.deltaTime,
Space.World); 21.
22.
transform.Rotate(rollSpeed * Time.deltaTime,
23.
0, 0, Space.World);
24.
} else if(Input.GetKey(KeyCode.DownArrow)){
25.
transform.Translate(0, 0,
26.
-moveSpeed
*
Time.deltaTime,
Space.World); 27.
28.
transform.Rotate(-rollSpeed * Time.deltaTime,
29.
0, 0, Space.World);
30.
}
31.
32.
//Move along global z axis and roll around global x axis
33.
if(Input.GetKey(KeyCode.RightArrow)){
34.
transform.Translate(moveSpeed
*
Time.deltaTime,
Search WWH ::




Custom Search