unity 2d player move
A new jorney beginsHow to make your player move unity 2D
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Obstacle : MonoBehaviour
{
    public float moveSpeed = 8; // Speed you want your Player to move at
    Rigidbody2D myrb; // to access the Rigidbody component
    float h; // to access the Input Axis
    void Start()
    {
        myrb = GetComponent<Rigidbody2D>();
    }
    void Update()
    {
        h = Input.GetAxis("Horizontal"); // moves by 1 or -1 when pressing d or a 
        Vector2 playerPos = new Vector2(h * moveSpeed, myrb.velocity.y); // move to the right or left
        myrb.velocity = playerPos; 
    }
}Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us
