问题
lineRenderer.SetWidth(startWidth, endWidth);
lineRenderer.SetVertexCount(linePoints.Count);
On both lines same warning:
'LineRenderer.SetVertexCount(int)' is obsolete: 'SetVertexCount has been deprecated. Please use the numPositions property instead.'
And
'LineRenderer.SetWidth(float, float)' is obsolete: 'SetWidth has been deprecated. Please use the startWidth, endWidth, or widthCurve properties instead.'
I tried this then:
lineRenderer.startWidth(startWidth, endWidth);
But then getting error on startWidth property:
'LineRenderer.startWidth' cannot be used like a method.
回答1:
Some of the LineRenderer
functions has been changed to properties and also renamed to avoid confusion. You set properties not call it as a function. For lineRenderer.SetVertexCount
, you use lineRenderer.positionCount
to set that.
lineRenderer.startWidth = startWidth;
lineRenderer.endWidth = endWidth;
lineRenderer.positionCount = linePoints.Count;
回答2:
Just do what the compiler is suggesting.
I.E.:
lineRenderer.startWidth = startWidth;
lineRenderer.endWidth = endWidth;
lineRenderer.positionCount = linePoints.Count;
来源:https://stackoverflow.com/questions/44442631/im-getting-warning-on-linerenderer-setwidth-that-its-obsolete-how-should-i-fix