UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"create a movement script for a 3d cube"
using UnityEngine; public class CubeMovement : MonoBehaviour { public float moveSpeed = 5f; private Rigidbody rb; // Start is called before the first frame update void Start() { rb = GetComponent<Rigidbody>(); } // Update is called once per frame void Update() { float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); rb.AddForce(movement * moveSpeed); } }