37 lines
1.0 KiB
C#
37 lines
1.0 KiB
C#
|
using UnityEngine;
|
|||
|
using System.Collections;
|
|||
|
|
|||
|
public class PlayerController : MonoBehaviour {
|
|||
|
|
|||
|
public Camera CameraObject;
|
|||
|
|
|||
|
public float MovementDelta;
|
|||
|
|
|||
|
// Use this for initialization
|
|||
|
void Start () {
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
// Update is called once per frame
|
|||
|
void Update () {
|
|||
|
|
|||
|
// Center camera on player
|
|||
|
var playerCoords = gameObject.transform.position;
|
|||
|
CameraObject.transform.position = new Vector3(playerCoords.x, playerCoords.y, CameraObject.transform.position.z);
|
|||
|
|
|||
|
// Handle movement keys
|
|||
|
float deltaX = 0, deltaY = 0;
|
|||
|
|
|||
|
if (Input.GetKey(KeyCode.DownArrow))
|
|||
|
deltaY -= MovementDelta * Time.deltaTime;
|
|||
|
if (Input.GetKey(KeyCode.UpArrow))
|
|||
|
deltaY += MovementDelta * Time.deltaTime;
|
|||
|
if (Input.GetKey(KeyCode.LeftArrow))
|
|||
|
deltaX -= MovementDelta * Time.deltaTime;
|
|||
|
if (Input.GetKey(KeyCode.RightArrow))
|
|||
|
deltaX += MovementDelta * Time.deltaTime;
|
|||
|
|
|||
|
gameObject.transform.Translate(deltaX, deltaY, 0);
|
|||
|
}
|
|||
|
}
|