using UnityEngine;
using System.Collections; public class CubeAddForce : MonoBehaviour { float hor,ver;
//力的方向向量
Vector3 forceDir;
//力的大小
public float force = ; Rigidbody rig; void Start()
{
rig = GetComponent<Rigidbody> ();
} void Update()
{
hor = Input.GetAxis ("Horizontal");
ver = Input.GetAxis ("Vertical"); forceDir = new Vector3 (hor,,ver);
//施加一个力
rig.AddForce (forceDir * force);
if (Input.GetKeyDown (KeyCode.Space)) {
rig.AddExplosionForce (, Vector3.zero, );
}
} }

AddForce给物体添加刚体效果并且脚本增加一个力(按空格实现)-LMLPHP

05-08 08:02