Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MoveCube : MonoBehaviour
- {
- public float speed;
- // Update is called once per frame
- void Update()
- {
- Vector3 offset = Vector3.zero;
- if (Input.GetKey(KeyCode.LeftShift))
- {
- if (Input.GetKey(KeyCode.UpArrow))
- {
- offset += Vector3.forward;
- }
- if (Input.GetKey(KeyCode.DownArrow))
- {
- offset -= Vector3.forward;
- }
- }
- else
- {
- if (Input.GetKey(KeyCode.UpArrow))
- {
- offset += Vector3.up;
- }
- if (Input.GetKey(KeyCode.DownArrow))
- {
- offset -= Vector3.up;
- }
- }
- if (Input.GetKey(KeyCode.LeftArrow))
- {
- offset -= Vector3.right;
- }
- if (Input.GetKey(KeyCode.RightArrow))
- {
- offset += Vector3.right;
- }
- // apply offset
- transform.position += offset * Time.deltaTime * speed;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement