slicing not supported since upgrade to unity 5.

I have this line of script:

animation[“attack”].layer = 1;

Before updating to unity 5 my code worked fine and now I get the following error:

Assets/Scripts/ThirdPersonController.js(18,1): BCE0048: Type ‘UnityEngine.Component’ does not support slicing.

Im a coding newb and this is confusing the hell out of me, anyone got any answer for me? The simpler explained the better :slight_smile:

thanks!

For quite some time Unity was announcing that they will remove the shortcut properties like rigidbody, animation, collider, audioSource, ect. The only one that will stay is “transform” as every GameObject always have a Transform component.

So from now on you have to use GetComponent to get access to another component on a gameobject.

So instead of

animation["attack"].layer = 1;

You would have to do this:

// UnityScript
var anim = GetComponent(Animation);
anim["attack"].layer = 1;

If you use a component more than once in the script you might want to move the GetComponent part into Awake or Start and store it in a class variable:

var anim : Animation;
function Awake()
{
    anim = GetComponent(Animation);
}

Now you can use “anim” instead of the old shortcut property “animation” inside that script.

GetComponent()