小编Ale*_*RED的帖子

Unity3d Linerenderer 不可见

我正在尝试使用 Linerenderer 在两个 UI 游戏对象之间画一条线。在场景模式下一切正常,但在游戏模式下线是不可见的。我试图改变对象的 Z 位置,但线条仍然不可见。谁能帮我?提前致谢

private LineRenderer lineRenderer;
private float counter;
private float dist;
private Vector3 aPos;
private Vector3 bPos;
public Transform origin;
public Transform destination;
public float lineDrawSpeed = 6f;

// Use this for initialization
void Start()
{
    lineRenderer = GetComponent<LineRenderer>();
    aPos = new Vector3(origin.position.x, origin.position.y, origin.position.z); // Using these to move the lines back
    bPos = new Vector3(destination.position.x, destination.position.y, destination.position.z);

    lineRenderer.SetPosition(0, aPos);
    lineRenderer.SetWidth(3f, 3f);

    dist = Vector3.Distance(origin.position, destination.position);
}

// Update is called once per frame …
Run Code Online (Sandbox Code Playgroud)

unity-game-engine unity5

6
推荐指数
2
解决办法
1万
查看次数

Unity Recttransform包含点

有没有一种方法可以检查Rect变换是否包含点?提前致谢。我尝试了Bounds.Contains()和RectTransformUtility.RectangleContainsScreenPoint(),但这对我没有帮助

private bool AreCoordsWithinUiObject(Vector2 coords, GameObject gameObj)
{
    Bounds bounds = gameObj.GetComponent<Renderer>().bounds;
    return bounds.Contains(new Vector3(coords.x, coords.y, 0));
}
Run Code Online (Sandbox Code Playgroud)

这样我有一个错误“没有渲染器附加到对象”,但是我已经将CanvasRenderer附加到它了。

RectTransformUtility.RectangleContainsScreenPoint(gameObj.GetComponent<RectTransform>(), coords);
Run Code Online (Sandbox Code Playgroud)

此方法总是返回false

if (AreCoordsWithinUiObject(point, lines[i]))
{
    print("contains");
}
Run Code Online (Sandbox Code Playgroud)

行是GameObjects的列表

在此处输入图片说明

c# unity-game-engine

1
推荐指数
1
解决办法
3594
查看次数

标签 统计

unity-game-engine ×2

c# ×1

unity5 ×1