Create a sphere as the protagonist of the game, name it player, and also create a material ball:
Add a Rigidbody component to the object:
Next, write a script code to control the walking of game objects:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class move : MonoBehaviour
{
// Start is called before the first frame update
public Rigidbody rd; //定义一个属性 在面板上面就有了 就可以赋值刚体 也可以通过代码赋值
void Start()
{
rd = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
float h=Input.GetAxis("Horizontal");
float v=Input.GetAxis("Vertical");
rd.AddForce(new Vector3(h,0,v)*10);
}
}