diff --git a/3D/Movement/Basic Cube/CubeMovement.c# b/3D/Movement/Basic Cube/CubeMovement.c# new file mode 100644 index 0000000..7ca42af --- /dev/null +++ b/3D/Movement/Basic Cube/CubeMovement.c# @@ -0,0 +1,19 @@ +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); + } +} diff --git a/3D/Movement/Basic Cube/instructions.md b/3D/Movement/Basic Cube/instructions.md new file mode 100644 index 0000000..d7fa931 --- /dev/null +++ b/3D/Movement/Basic Cube/instructions.md @@ -0,0 +1,5 @@ +To use this script, follow these steps: + +In Unity, create a 3D cube GameObject by going to GameObject -> 3D Object -> Cube. + +Attach the script to the cube GameObject by dragging and dropping the script onto the cube in the Hierarchy or using the `Add Component \ No newline at end of file