我有 raycast 和 rayCastHit。每当用户点击开火按钮时。它会将 FPS 字符移动到 rayCastHit 所在的位置。lightRetical 是一个 gameObject 变量,它是一个聚光灯,显示 rayCastHit 的位置。
有趣的是,当我点击统一播放时,它会起作用。但是,每当我构建到我的 android 手机时,它都不起作用。我无法移动 fps 角色。
我使用的 FPS 字符来自标准资产“字符”以及我将它们添加到 Update() 方法的代码。
RaycastHit seen;
Ray raydirection = new Ray(transform.position, cam.transform.forward);
int sightlength = 5;
if (Physics.Raycast(raydirection, out seen, sightlength))
{
if (seen.collider.tag == "Floor" && Input.GetButtonDown("Fire1")) //in the editor, tag anything you want to interact with and use it here
{
Vector3 relativePoint;
lightRetical.SetActive(true);
relativePoint = seen.point;
relativePoint.y = 2.0f;
bodychar.transform.position = relativePoint;
}
else
{
lightRetical.SetActive(true);
Vector3 relativePoint;
relativePoint = seen.point;
relativePoint.y = 2.64f;
lightRetical.transform.position = relativePoint;
}
}
else
{
lightRetical.SetActive(false);
}