mirror of
https://github.com/CodeninjasWS/Usefull-Unity-Scripts.git
synced 2025-07-17 17:41:57 -04:00
20 lines
587 B
Text
20 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);
|
||
|
}
|
||
|
}
|