Last active
February 24, 2016 09:04
-
-
Save scorta/0869e5c4fe689283ada1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class CameraController : MonoBehaviour | |
{ | |
public float moveSpeed, zoomSpeed; | |
private Rigidbody rb; | |
void Start () | |
{ | |
rb = gameObject.GetComponent<Rigidbody>(); | |
} | |
void FixedUpdate() | |
{ | |
Move(); | |
Zoom(); | |
} | |
private void Move() | |
{ | |
float moveHorizontal = Input.GetAxis("Horizontal"); | |
float moveVertical = Input.GetAxis("Vertical"); | |
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); | |
rb.velocity = movement * moveSpeed; | |
} | |
private void Zoom() | |
{ | |
float zoomIn = Input.GetAxis("Fire1"); | |
float zoomOut = Input.GetAxis("Fire2"); | |
Vector3 zoom = transform.forward; | |
if (zoomIn != 0) | |
{ | |
rb.velocity = zoom * zoomSpeed; | |
} | |
else if (zoomOut != 0) | |
{ | |
rb.velocity = -1 * zoom * zoomSpeed; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment