using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovePlayer : MonoBehaviour
{
private Rigidbody rb;
public float speed = 0.5f;
private Vector3 moveVector;
public Rigidbody Rb { get => rb; set => rb = value; }
void Awake()
{
rb = GetComponent<Rigidbody>();
if (rb == null)
{
Debug.LogError("Rigidbody component is missing on the player object.");
}
moveVector = Vector3.zero;
}
void Update()
{
moveVector.x = Input.GetAxis("Horizontal");
moveVector.z = Input.GetAxis("Vertical");
rb.MovePosition(rb.position + moveVector * speed * Time.deltaTime);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovePlayer : MonoBehaviour
{
private Rigidbody rb;
public float speed = 0.5f;
private Vector3 moveVector;
public Rigidbody Rb { get => rb; set => rb = value; }
void Awake()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
moveVector.x = Input.GetAxis("Horizontal");
moveVector.z = Input.GetAxis("Vertical");
rb.MovePosition(rb.position + moveVector * speed * Time.deltaTime);
}
}