mirror of
https://github.com/CodeninjasWS/Usefull-Unity-Scripts.git
synced 2025-07-05 16:00:20 -04:00
19 lines
587 B
Text
19 lines
587 B
Text
using UnityEngine;
|
|
|
|
public class CubeMovement : MonoBehaviour
|
|
{
|
|
public float movementSpeed = 5f;
|
|
|
|
void Update()
|
|
{
|
|
// Get input from keyboard or arrow keys
|
|
float horizontalInput = Input.GetAxis("Horizontal");
|
|
float verticalInput = Input.GetAxis("Vertical");
|
|
|
|
// Calculate the movement direction
|
|
Vector3 movementDirection = new Vector3(horizontalInput, 0f, verticalInput).normalized;
|
|
|
|
// Move the cube based on the input and movement speed
|
|
transform.Translate(movementDirection * movementSpeed * Time.deltaTime);
|
|
}
|
|
}
|