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