有没有办法检查Rect变换是否包含点?提前致谢。我试图Bounds.Contains()和RectTransformUtility.RectangleContainsScreenPoint(),但没有帮助我Unity Recttransform包含点
private bool AreCoordsWithinUiObject(Vector2 coords, GameObject gameObj)
{
Bounds bounds = gameObj.GetComponent<Renderer>().bounds;
return bounds.Contains(new Vector3(coords.x, coords.y, 0));
}
这样,我有一个错误“没有附着在物体渲染”,但我已经连接CanvasRenderer到它。
RectTransformUtility.RectangleContainsScreenPoint(gameObj.GetComponent<RectTransform>(), coords);
此方法总是返回false
if (AreCoordsWithinUiObject(point, lines[i]))
{
print("contains");
}
线是GameObjects
请包括您尝试的代码。你的问题只是一个功能。把代码不起作用。 “Bounds.Contains”和“RectTransformUtility.RectangleContainsScreenPoint”都有人可能会发现你的问题。 – Programmer
我使用代码 –
更新了帖子也许是因为您试图获得“渲染器”而不是“CanvasRenderer”? –