1.创建一个平面和一个球,在下图区域中右键选择3D object→plane;3D object→spher2.给小球加刚体,在下图区域中点击Add Component→Rigidbody
3.给小球编辑脚本,点击spher→Add Component→给脚本命名题目可随意4.编写让小球移动的脚本
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));
}
}
5.点击开始就可以使小球移动了
以上内容到此结束感谢观看!