var useGravity : bool
Description描述
Controls whether gravity affects this rigidbody.
控制重力是否影响整个刚体。
If set to false the rigidbody will behave as in outer space.
如果设置为false,刚体将不受重力影响。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void OnTriggerEnter(Collider other) {
if (other.attachedRigidbody)
other.attachedRigidbody.useGravity = false;
}
public void Awake() {
collider.isTrigger = true;
}
}
// Disables gravity on all rigid bodies entering this collider.
//当所有刚体进入这个碰撞器,禁用重力
function OnTriggerEnter (other : Collider) {
if (other.attachedRigidbody) {
other.attachedRigidbody.useGravity = false;
}
}
// Turn this collider into a trigger on startup
//启动时把碰撞器变为触发器
collider.isTrigger = true;