mirror of
https://github.com/CodeninjasWS/Usefull-Unity-Scripts.git
synced 2025-07-03 06:50:23 -04:00
Added cube movement
This commit is contained in:
parent
30367b3c3e
commit
c4cc829da3
2 changed files with 24 additions and 0 deletions
3D/Movement/Basic Cube
19
3D/Movement/Basic Cube/CubeMovement.c#
Normal file
19
3D/Movement/Basic Cube/CubeMovement.c#
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
5
3D/Movement/Basic Cube/instructions.md
Normal file
5
3D/Movement/Basic Cube/instructions.md
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue