mirror of
https://github.com/CodeninjasWS/Usefull-Unity-Scripts.git
synced 2025-06-15 22:20:30 -04:00
19 lines
614 B
C#
19 lines
614 B
C#
using UnityEngine;
|
|
|
|
public class CubeMovement : MonoBehaviour
|
|
{
|
|
public float moveSpeed = 5f;
|
|
|
|
private void Update()
|
|
{
|
|
// Get input for movement in both horizontal and vertical axes
|
|
float horizontalInput = Input.GetAxis("Horizontal");
|
|
float verticalInput = Input.GetAxis("Vertical");
|
|
|
|
// Calculate the movement direction based on input
|
|
Vector3 movementDirection = new Vector3(horizontalInput, 0f, verticalInput).normalized;
|
|
|
|
// Move the cube in the calculated direction
|
|
transform.Translate(movementDirection * moveSpeed * Time.deltaTime);
|
|
}
|
|
}
|