Array length wont become updated,My array length is zero and wont change
my array has a length of zero even though length is set to 20 and I update segment pose in the start function.
public class Tentacle : MonoBehaviour
{
public int length = 20;
public LineRenderer lineRend;
public Vector3[] segmentPose;
public Transform targetDir;
public float targetDist;
private Vector3[] segment5;
public float smoothSpeed;
private void start()
{
lineRend.positionCount = length;
segmentPose = new Vector3[length];
segment5 = new Vector3[length];
}
// Update is called once per frame
private void Update()
{
Debug.Log(segmentPose.Length);
segmentPose[0] = targetDir.position;
for (int i = 1; i < segmentPose.Length; i++)
{
segmentPose[i] = Vector3.SmoothDamp(segmentPose[i], segmentPose[i-1] + targetDir.right * targetDist, ref segment5[i], smoothSpeed);
}
lineRend.SetPositions(segmentPose);
}
}
debug says it still has 0 length ,My array length is stuck at zero and wont change, what am I doing wrong my length int is set 20
segmentPose = new Vector3[length]; this code is in my start function
Answer by xxmariofer · Feb 11 at 11:26 AM
the code is fine, change from
public Vector3[] segmentPose;
to
private Vector3[] segmentPose;
to know hwere you are changing segmentPose. if no errors appear when you change from private it should work fine, maybe somewhere else you are overriding its value
Your answer

Follow this Question
Related Questions
Need help comparing arrays/lists to show items that are missing from one of them 2 Answers
Cycling through array not working. Pulling my hair over this one. 0 Answers
Fill Array Of Arrays With Method/Function 0 Answers
Weird blurry texture, how do I fix :)? 1 Answer
How to check if dragged object collide with other object? 0 Answers