Usefull-Unity-Scripts/3D/Movement/Basic Cube/CubeMovement.c#

20 lines
587 B
Text
Raw Permalink Normal View History

2023-07-31 18:39:27 -06:00
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);
}
}