Roll A Ball通过代码控制移动
建立Player脚本 把Player脚本移到物体Player身上
具体控制移动代码如下
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
private Rigidbody rd; //声明一个钢体组件rd (通过rd去操作组件)
void Start()
{
rd = GetComponent<Rigidbody>(); //得到游戏物体的钢体组件并赋给rd
}
// Update is called once per frame
void Update()
{
rd.AddForce(new Vector3(1, 0, 0)); // 让它一直运动 通过 . 去调用方法
//new Vector3(x,y,z)创建1个向量(一个向量有3个值)
}
}