- Home /
Dynamic array length problem.Why my code generate error?
Hi to all.
In my project i have some dynamic array of animationclip for holding character animations.my script is such bellow:
public AnimationClip[] idleanimations;
public AnimationClip[] walkanimations;
public AnimationClip[] attackanimations;
public AnimationClip[] escapeanimations;
public AnimationClip[] alertanimations;
and in start function of my script i do some check to see are those arrays have any value or not,like this code:
if(idleanimations.Length==0)
{
_animation=null;
Debug.Log("No idle animations found. Turning off animations.");
}
.
.
.
if(walkanimations.Length==0)
{
_animation=null;
Debug.Log("No walk animations found. Turning off animations.");
}
and until this point there isn't any error.But this is strange! this line of code does not cause any error:
temp=idleanimations.Length;
for(int i=0;i<temp;i++)
{
_animation.AddClip(idleanimations[i],idleanimations[i].name);
}
but bellow codes that are exactly the same method generate error:
temp=walkanimations.length; //this line generate error for(int i=0;i
I don't know why my post didn't display completely,so i post remaining lines here:
temp=walkanimations.length; //this line generate error
for(int i=0;i<temp;i++)
{
_animation.AddClip(walkanimations[i],walkanimations[i].name);
}
temp=attackanimations.length; //this line generate error
for(int i=0;i<temp;i++)
{
_animation.AddClip(attackanimations[i],attackanimations[i].name);
}
temp=escapeanimations.length; //this line generate error
for(int i=0;i<temp;i++)
{
_animation.AddClip(escapeanimations[i],escapeanimations[i].name);
}
temp=alertanimations.length; //this line generate error
for(int i=0;i<temp;i++)
{
_animation.AddClip(alertanimations[i],alertanimations[i].name);
}
and error message is:
Assets/staff/scripts/SimpleAIController.cs(73,29): error CS1061: Type UnityEngine.AnimationClip[]' does not contain a definition for
length' and no extension method length' of type
UnityEngine.AnimationClip[]' could be found (are you missing a using directive or an assembly reference?)
I'm really confused and do not know what is the cause.
excuse me for my long post and i would be grateful of any help or advice.
Answer by pixelsyntax · May 27, 2013 at 08:35 PM
Case sensitivity. You need to change length
to Length
:)
Thanks a lot 1000 times. only must say that i use monodevelop for editing scripts and by code completion that error Happened.
Your answer
![](https://koobas.hobune.stream/wayback/20220613103023im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
2D Array Rigidbody details storing error - C# 1 Answer
NullReferenceException error 1 Answer
Can't get list to work (simple) 1 Answer
Animation error (Last time I'm asking) 2 Answers