Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MovimientoHorizontal : MonoBehaviour
- {
- public float velocidad = 5f;
- private Rigidbody2D rb;
- private float movimiento;
- void Start()
- {
- rb = GetComponent<Rigidbody2D>();
- }
- void Update()
- {
- // Movimiento horizontal con teclas A/D o flechas izquierda/derecha
- movimiento = Input.GetAxisRaw("Horizontal");
- }
- void FixedUpdate()
- {
- // Solo se mueve en el eje X
- rb.velocity = new Vector2(movimiento * velocidad, rb.velocity.y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement