Esempio n. 1
0
    public static void DrawLine(Vector3 start, Vector3 end, Color color, float duration = 0, float width = 1)
    {
        //early out if there is no Camera.main to calculate the width
        if (!Camera.main)
        {
            return;
        }

        GameObject line = new GameObject("debug_line");

        //set the params of the line renderer - http://docs.unity3d.com/Documentation/ScriptReference/LineRenderer.html
        LineRenderer lineRenderer = line.AddComponent <LineRenderer>();

        lineRenderer.material = new Material(Shader.Find("Mobile/Particles/Additive"));
        lineRenderer.SetPosition(0, start);
        lineRenderer.SetPosition(1, end);
        lineRenderer.SetColors(color, color);
        lineRenderer.SetWidth(DebugLine.CalcPixelHeightAtDist((start - Camera.main.transform.position).magnitude) * width,
                              DebugLine.CalcPixelHeightAtDist((end - Camera.main.transform.position).magnitude) * width);

        //add the MonoBehaviour instance
        DebugLine debugLine = line.AddComponent <DebugLine>();

        //set the time to expire - default is 0 (will only draw for one update cycle)
        //use Update or FixedUpdate depending on the time of the invoking call
        if (Time.deltaTime == Time.fixedDeltaTime)
        {
            debugLine.fixed_destroy_time = Time.fixedTime + duration;
        }
        else
        {
            debugLine.destroy_time = Time.time + duration;
        }
    }
Esempio n. 2
0
    public static void DrawLine(
        Vector3 start,
        Vector3 end,
        Color color,
        Color endColor,
        float duration    = 0,
        float width       = 1,
        Material material = null)
    {
        if (!Camera.main)
        {
            return;
        }
        if (!material)
        {
            material = new Material(Shader.Find("Particles/Additive"));
        }
        var instance = new GameObject("sound ray");
        var line     = instance.AddComponent <LineRenderer>();

        line.material = material;
        line.SetPosition(0, start);
        line.SetPosition(1, end);
        line.SetColors(color, endColor);
        line.SetWidth(DebugLine.CalcPixelHeightAtDist(
                          (start - Camera.main.transform.position).magnitude) * width,
                      DebugLine.CalcPixelHeightAtDist(
                          (end - Camera.main.transform.position).magnitude) * width);
        instance.AddComponent <DebugLine>().lifetime = duration;
    }