﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MoveAndLook : MonoBehaviour
{
    CharacterController controller;
    // Start is called before the first frame update
    void Start()
    {
        controller = GetComponent<CharacterController>();
    }

    Vector2 rotation = Vector2.zero;
    public float mouseSpeed = 3;
    public float speed = 50;

    void Update()
    {
        rotation.y += Input.GetAxis("Mouse X");
        rotation.x += -Input.GetAxis("Mouse Y");
        
        transform.eulerAngles = (Vector2)rotation * mouseSpeed;

        var x = Input.GetAxis("Horizontal");
        var z = Input.GetAxis("Vertical");
        var move = transform.right * x + transform.forward * z;
        move.y = 0.0f;
        controller.Move(move * speed * Time.deltaTime);
    }
}
