【问题标题】:How to draw a line with arrow using touch in unity?如何使用统一的触摸画一条带箭头的线?
【发布时间】:2019-09-10 08:50:06
【问题描述】:

我正在寻找一条包含箭头标记的线。如何用箭头显示它是一个问题。是否可以不使用线渲染器?

在此处附加一个链接以在屏幕上显示线条的绘制。Draw Arrow。如果我向右滑动箭头指向右侧并在屏幕上手持我可以更改箭头的位置。一旦我释放箭头位置是固定的。

我已经在两点之间画了一条线。代码如下。

if (Input.GetTouch(0).phase == TouchPhase.Began)
    {


        //--Clearing the list and adding first touch to list--
        fingerPositions.Clear();
        fingerPositions.Add(Camera.main.ScreenToWorldPoint(Input.mousePosition));
        Debug.Log("Made first touch");
        click = true;
    }

    if (Input.GetTouch(0).phase == TouchPhase.Moved)
    {
        isSwiping = true;


    }

    if (Input.GetTouch(0).phase == TouchPhase.Ended && isSwiping == true)
    {
        //--Adding the last touch to the list--
        fingerPositions.Add(Camera.main.ScreenToWorldPoint(Input.mousePosition));
        //currenline is GameObject
        currenline = Instantiate(linePrefab, fingerPositions[0], Quaternion.identity);
        getAllLines.Add(currenline);
        //NewLine is a LineRenderer
        NewLine = currenline.GetComponent<LineRenderer>();

        Debug.Log("Finger count = "+fingerPositions.Count);

        NewLine.SetPosition(0, fingerPositions[0]);
        NewLine.SetPosition(1, fingerPositions[1]);




        isSwiping = false;
    }

【问题讨论】:

    标签: c# unity3d touch draw


    【解决方案1】:

    在你的线预制件中添加一个三角形精灵,它被锚定到预制件的末端边缘。如果它是一个孩子,它会保持它的方向,所以你只需要创建线条和箭头就会跟随。

    【讨论】:

    • 我创建了一个画布图像并添加为 LineRenderer 的子元素 ..但是当我最初设置时实例化箭头保持方向。它不会改变方向。
    • @zyonneo 我以为你有一个带箭头的预制件。无论如何,您可以通过计算angle between 箭头矢量和箭头精灵的方向来做到这一点。然后,您可以将箭头的局部旋转(欧拉角)更新为正确轴上的值。
    • 我正在使用 Line 渲染器来绘制线条。
    • @zyonneo 是的。上述解决方案应该有效。试一试。
    • 任何例子...只能用线渲染器画线
    猜你喜欢
    • 2015-09-28
    • 2011-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-25
    • 2016-04-18
    • 2023-03-25
    相关资源
    最近更新 更多