1.首先进行场景布置,创建好障碍物、平面、墙体、小球并设置好自己喜欢的颜色。
2.然后选中球,在右栏点击add component 搜索rigidbody属性赋予小球钢体
3.右键选中Create中的C#Script创建让小球移动的脚本
4.脚本命名为move并编写如图代码
代码仅供参考
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move : MonoBehaviour
{
public Rigidbody rg;
// Start is called before the first frame update
void Start()
{
rg = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
rg.AddForce(new Vector3(h, 0, v));
}
}