-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cs
More file actions
34 lines (29 loc) · 917 Bytes
/
Player.cs
File metadata and controls
34 lines (29 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
float speed = 3;
Camera MainCam;
// Use this for initialization
void Start () {
MainCam = (Camera)GameObject.Find ("Main Camera").GetComponent<Camera> ();
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.UpArrow)) {
transform.Translate(0f,0f,speed * Time.deltaTime);
}
else if (Input.GetKey(KeyCode.DownArrow)) {
transform.Translate(0f,0f,-speed * Time.deltaTime);
}
else if (Input.GetKey(KeyCode.RightArrow)) {
transform.Translate(speed * Time.deltaTime,0f,0f);
}
else if (Input.GetKey(KeyCode.LeftArrow)) {
transform.Translate(-speed * Time.deltaTime,0f,0f);
}
float horizontal = 3.0f * Input.GetAxis("Mouse X");
float vertical = 3.0f * Input.GetAxis("Mouse Y");
transform.Rotate(0f, horizontal, 0f);
MainCam.transform.Rotate(-vertical, 0f, 0f);
}
}