Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Player : MonoBehaviour
- {
- public float movementSpeed = 10f;
- public float rotateSpeed = 200f;
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- Movement();
- }
- private void Movement()
- {
- float x = 0, y = 0, z = 0;
- if (Input.GetKey(KeyCode.W))
- {
- z = 1;
- }
- else if (Input.GetKey(KeyCode.S))
- {
- z = -1;
- }
- else if (Input.GetKey(KeyCode.A))
- {
- y = -1;
- }
- else if (Input.GetKey(KeyCode.D))
- {
- y = 1;
- }
- Vector3 vector = new Vector3(x, 0, z) * Time.deltaTime * movementSpeed;
- Vector3 rotation = new Vector3(0, y, 0) * Time.deltaTime * rotateSpeed;
- transform.Translate(vector);
- transform.Rotate(rotation);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement