unity-game-engine - 我们如何为 linerenderer 设置白色

标签 unity-game-engine swipe

我是 Unity 的新手,我已经设置了滑动屏幕时应该出现的线条的宽度和颜色。但它不起作用,不知道我的代码是否错误

using UnityEngine;
using System.Collections;

public class LinesHandler : MonoBehaviour
{
    public Color c1 = Color.yellow;
    public Color c2 = Color.red;

    private GameObject lineGO;
    private LineRenderer lineRenderer;
    private int i = 0;

    void Start()
    {
        lineGO = new GameObject("Line");
        lineGO.AddComponent<LineRenderer>();
        lineRenderer = lineGO.GetComponent<LineRenderer>();
        lineRenderer.material = new Material(Shader.Find("Mobile/Particles/Additive"));
        //lineRenderer.SetColors(c1, c2);
        lineRenderer.SetWidth(0.05F, 0);
        lineRenderer.SetVertexCount(0);
    }

    void Update()
    {
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            if(touch.phase == TouchPhase.Moved)
            {
                lineRenderer.SetVertexCount(i+1);
                Vector3 mPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 15);
                lineRenderer.SetPosition(i, Camera.main.ScreenToWorldPoint(mPosition));
                i++;

                /* Add Collider */

                BoxCollider bc = lineGO.AddComponent<BoxCollider>();
                bc.transform.position = lineRenderer.transform.position;
                bc.size = new Vector3(0.1f, 0.1f, 0.1f);
            }

            if(touch.phase == TouchPhase.Ended)
            {
                /* Remove Line */

                lineRenderer.SetVertexCount(0);
                i = 0;

                /* Remove Line Colliders */

                BoxCollider[] lineColliders = lineGO.GetComponents<BoxCollider>();

                foreach(BoxCollider b in lineColliders)
                {
                    Destroy(b);
                }
            }
        }
    }
}

现在我在屏幕上滑动时出现粉红色线条。如何将该颜色更改为白色。
还可以减少线的宽度...

最佳答案

显然你的设置是正确的,但是当 Material 缺失时,粉色是默认 Material 。我想只是它找不到您要应用的 Material 。

您应该检查this出来。

您还将找到宽度和颜色的示例。

关于unity-game-engine - 我们如何为 linerenderer 设置白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39872417/

相关文章:

android - 谷歌纸板的最小android api

android - 使用 Android 6.0.1 但不是 5.1.1 的 Galaxy S6 上的 Gear VR 应用程序中的 TBE 音频跳过

android - 无法从阵列适配器设置 SwipeFlingAdapterView

android - 我应该在哪里为 Main Activity 实现 setOnTouchListener

android - 如何在没有 View 的情况下在Android游戏中实现滑动

c# - 如何在 for 循环中等待 x 秒 C# - unity

unity-game-engine - HoloLens 应用程序突然不再启动!错误: "Failed to load game Assembly"

firebase - Unity 和 Firebase - 程序包管理器解析程序,正在卸载以下程序包 : Firebase Authentication

ios - 在 uiscrollview 中滑动不能正常工作

iphone - iPhone SDK 4.0 中的滑动手势?