unity控制物体移动
player.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player : MonoBehaviour
{
private float horizontalInput;
private Rigidbody rigidbodyComponent;
// Start is called before the first frame update
void Start()
{
rigidbodyComponent = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
horizontalInput = Input.GetAxis("Horizontal");
}
private void FixedUpdate()
{
rigidbodyComponent.velocity = new Vector3(horizontalInput, rigidbodyComponent.velocity.y , 0);
}
}