- Home /
How to set startWidth and endWidth of LineRenderer in Unity 5.5.1f1?
I used to use lineRenderer.SetWidth() before upgrading to Unity 5.5.1f1 and it was working well. I upgraded and changed this code:
lineRenderer.SetWidth(scale, scale);
to next:
lineRenderer.startWidth = scale;
lineRenderer.endWidth = scale;
It works, but not always. A value in Inspector changes, but it doesn't get reflected in Game. When I update the value to the same (without changing it) in Inspector, it gets reflected. It feels like a bug. Note: I enable/disable Line Renderer components in Game at runtime.
Answer by Ziya · Feb 17, 2017 at 09:12 AM
Change the code to the next:
AnimationCurve curve = new AnimationCurve();
curve.AddKey(0, scale);
curve.AddKey(1, scale);
lineRenderer.widthCurve = curve;
Note: You should create new KeyFrame instances every time you set width. If you modify existing ones, it doesn't work.
Answer by pranesh-arry · May 02, 2018 at 12:34 PM
Download this script and attach it to the object containing the LineRenderer Component-
Download File "LineRendererAdvancedOptions.cs"
yes, this is a C# script