Day #008

#DAY008

Using the camera as a movable first person player.

Main points covered

#characterController

#Input.getAxis

C# script (attached to the camera)

 

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

public class movecamera : MonoBehaviour {

public float speedmove;
private CharacterController controller;

// Use this for initialization
void Start () {
controller = GetComponent<CharacterController> ();

}

// Update is called once per frame
void Update () {

Vector3 move = Vector3.zero;
if (Input.GetKey (KeyCode.A)) {
move -= this.transform.right;
}

if (Input.GetKey (KeyCode.D)) {
move += this.transform.right;
}

if (Input.GetKey (KeyCode.W)) {
move += this.transform.forward;
}

if (Input.GetKey (KeyCode.S)) {
move -= this.transform.forward;
}

transform.Rotate(new Vector3(Input.GetAxis(“Mouse Y”)*-1, Input.GetAxis(“Mouse X”), 0));
controller.Move(move * Time.deltaTime * speedmove);

}

}

Leave a Reply

Your email address will not be published. Required fields are marked *