IMHOTEP Framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
MoveCamera.cs
1 using UnityEngine;
2 using System.Collections;
3 
4 public class MoveCamera : MonoBehaviour {
5 
6  public float speed = 5f;
7 
8  private Vector3 cameraStartPosition;
9 
10  // Use this for initialization
11  void Start () {
12  cameraStartPosition = Camera.main.transform.position;
13  }
14 
15  // Update is called once per frame
16  void Update () {
17  if(Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0)
18  {
19  Vector2 input = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
20 
21  if (input.sqrMagnitude > 1)
22  {
23  input.Normalize();
24  }
25 
26  Vector3 movement = Camera.main.transform.forward * input.y + Camera.main.transform.right * input.x;
27 
28  //if left shift is pressed, movement is 3 times faster
29  float shift = Input.GetKey(KeyCode.LeftShift) ? 3f : 1f;
30 
31  movement = movement * speed * shift;
32 
33  transform.localPosition = transform.localPosition + movement;
34  }
35 
36  if (Input.GetKeyDown(KeyCode.R))
37  {
38  Camera.main.transform.position = cameraStartPosition;
39  }
40 
41  }
42 }