我是 Unity 新手,但我有 1.5 年的 Java 经验。我了解大多数统一脚本的东西,但我仍在试图弄清楚如何以第一人称从场景中拾取对象。这是我用来拾取东西的东西,但我不知道如何告诉计算机要拾取哪个物体,谢谢!
#pragma strict
function Start () {
}
var SpawnTo : Transform;
var Object1 : Transform;
var dist = 4;
private var isHolding = false;
function Update () {
if(Input.GetKeyDown(KeyCode.E)){
if(Vector3.Distance(transform.position, Object1.position) < dist){
isHolding = !isHolding;
}
}
if(isHolding == true){
Object1.rigidbody.useGravity = false;
Object1.parent = SpawnTo;
Object1.transform.position = SpawnTo.transform.position;
Object1.transform.rotation = SpawnTo.transform.rotation;
}else{
SpawnTo.transform.DetachChildren();
Object1.rigidbody.useGravity = true;
}
}