using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class character : MonoBehaviour
{
private Rigidbody2D rb;
public float speed = 0.5f;
private Vector2 moveVector;
public float jumpForce = 5.0f;
void Awake()
{
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
MoveCharacter();
Jump();
}
void MoveCharacter()
{
moveVector.x = Input.GetAxis("Horizontal");
rb.MovePosition(rb.position + moveVector * speed * Time.deltaTime);
}
void Jump()
{
if (Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(new Vector2(1, jumpForce), ForceMode2D.Impulse);
}
}
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space)) Jump();
}
void Jump()
{
rb.AddForce(transform.up*jumpForce, ForceMode2D.Impulse);
}