【发布时间】:2023-03-05 23:12:01
【问题描述】:
这个游戏中的相机有一个目标,可以通过点击其他模型来改变,然后成为相机焦点,下面的脚本是我到目前为止得到的,但是每次我点击游戏中的一个对象时,目标只是说没有,而不是任何模型。
Ray toMouse = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
bool didHit = Physics.Raycast(toMouse, out hitInfo);
if (didHit)
{
if (hitInfo.collider.tag == "Cell" && Input.GetMouseButtonDown(0))
{
Debug.Log("Cell hit");
target = hitInfo.transform.Find(gameObject.name);
}
}
【问题讨论】:
-
什么是
gameObject.name?这里似乎缺少一些代码。 -
我认为可以将光线投射命中的对象名称转换为目标名称。
标签: c# unity3d camera raycasting