Simple Attack Script Problem

Hi everybody, I’m trying to learn about unity3d so, I’m making a simple game just to learning.

I’m having a hard time to scripting a attack script. Unity doesn’t have a attacking asset, 'cuz it may vary in a game (shoots, swords, kung fu)

Anyway, I’ve made a script that play the atack animation if I push left ctrl. See below.

function Update () {

if(Input.GetKeyDown(“left ctrl”)){



The problem is: It doesn’t play the full animation (the animation has 60 frames), so, how can I solve this?

Sorry for de dull question, I really wanna learn the unity scripting, but my way of learning, is praticing.

PS: Sorry for my English, I’m Brazilian.

Guys, I DID IT! I’ve just put the attack animation in another layer, now the animation is going well. I’m still having a problem with the CrossFade, but I’ll try another way.

You know, like attack walking or jumping. Maybe I should make a different animation for them, though.

The script is like this:

function Start () {

animation[“attack”].layer = 1; }

function Update () {

if(Input.GetKeyUp(“left ctrl”)){


Thanks to kristercollin, Gilead7 and Fattie, for your patience and kindness :slight_smile:

So, In the inspector, is already in play automatically. I’ve checked bake animation too ( i’m using IK), and I realize, it’s playing just ONE frame, not 10. Even if keep pressed the key down, just play one frame and stops. All the other animations is playing ok (idle, run and jumping)