xxxxxxxxxx
using UnityEngine;
public class PlayerMovement : MonoBehaviour // PlayerMovement is the name of the script
{
public float speed = 10;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
Vector2 pos = transform.position;
pos.x += h * Time.deltaTime * speed;
pos.y += v * Time.deltaTime * speed;
transform.position = pos;
}
}
xxxxxxxxxx
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovemeny : MonoBehaviour{
public float speed;
private Rigidbody2D rd;
void Start(){
rb = GetComponent<Rigidbody2D>();
}
void Update() {
Vector2 moveInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"))
moveVelocity = moveInput * speed;
}
void FixedUpdate(){
rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime);
}
}