mirror of
https://github.com/CodeninjasWS/Usefull-Unity-Scripts.git
synced 2025-06-28 20:50:19 -04:00
20 lines
614 B
C#
20 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);
|
||
|
}
|
||
|
}
|