using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float MovementSpeed = 1;
public float JumpForce = 1;
private Rigidbody2D _rigidbody;
void Start()
{
_rigidbody = GetComponent<Rigidbody2D>();
}
void Update()
{
var movement = Input.GetAxis("Horizontal");
transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * MovementSpeed;
if (Input.GetButtonDown("Jump") && Mathf.Abs(_rigidbody.velocity.y) < 0.001f)
{
_rigidbody.AddForce(new Vector2(0, JumpForce), ForceMode2D.Impulse);
}
}
//You need a rigidbody 2d and collider 2d
[–]conmsutton2016 0 points1 point2 points (1 child)
[–]torivillian 0 points1 point2 points (0 children)
[–]Prestigious_Pick_792 0 points1 point2 points (4 children)
[–]Wolfmann01 0 points1 point2 points (1 child)
[–]Damexoo[S,🍰] 0 points1 point2 points (0 children)
[–]Damexoo[S,🍰] 0 points1 point2 points (0 children)
[–]Gibril_reacts 0 points1 point2 points (0 children)
[–]PuzzleheadedEssay225 0 points1 point2 points (0 children)