Breaking

Friday, July 28, 2023

Super Mario 2d jump Code

 using System.Collections;

using System.Collections.Generic;
using UnityEngine;

public class PlayerMovent : MonoBehaviour
{
   private Rigidbody2D rb;
    //public float speed = 10f;
    // Start is called before the first frame update
   private  void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
   private void Update()
    {
        float dirX = Input.GetAxisRaw("Horizontal");
        rb.velocity = new Vector2(dirX * 7f,rb.velocity.y);
        if(Input.GetButtonDown("Jump"))
        {
            rb.velocity = new Vector2(rb.velocity.x, 14f);
        }
    }
}

No comments:

Post a Comment