我正在使用此代码进行立方体拾取和投掷,但是当我使用此代码来挑选预制模型(在我的情况下灭火器)时,它不起作用..请帮助我..代码附加到多维数据集。 实际上我想选择灭火器并想用来解决火灾,但我无法挑选灭火器。我正在使用灭火器的资产。
void start() {
mainCamera = GameObject.FindWithTag("MainCamera");
}
void Update()
{
if (carrying)
{
carry(carryObject);
checkDrop();
}
else
{
pickup();
}
}
void carry(GameObject o)
{
o.transform.position = Vector3.Lerp(o.transform.position,Camera.main.transform.position + Camera.main.transform.forward * distance,Time.deltaTime * smooth);
}
void pickup()
{
// PickupCube.Addcomponent(Rigidbody);
if (Input.GetKeyDown(KeyCode.F))
{
int x = Screen.width / 2;
int y = Screen.height / 2;
Ray ray =Camera.main.ScreenPointToRay(new Vector3(x, y));
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
PickupCube p = hit.collider.GetComponent<PickupCube>();
if (p != null)
{
carrying = true;
carryObject = p.gameObject;
p.gameObject.GetComponent<Rigidbody>().isKinematic = true;
}
}
}
}
// Update is called once per frame
void checkDrop(){
if (Input.GetKeyDown (KeyCode.F))
dropObject();
}
void dropObject(){
carrying = false;
carryObject.gameObject.GetComponent<Rigidbody>().isKinematic = false;
carryObject = null;
}
}