Script for keycode and animation

Hello can someone help me with 3D platformer game script for run attack animation after pressing the leftcontrol key ?

I tried reading the unity manual but it don’t work.

This one will run every time you press the left control button.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            //Your code in here
            Debug.Log("Left Control was pressed");
        }
    }
}

ok but what about running attack animation after pressing left control ?

Yeah, I’m not gonna write the whole game for you. There are many tutorials on how to do all this things, if AFTER following one of those you have some problem, come back to the forums with a detail explanation of your problem.

1 Like

And what’s your problem about it?

I have problem with script - after pressing left ctrl “attack” animation don’t run.

public class Attack : MonoBehaviour
{
// Use this for initialization
void Start()
{
anim = GetComponent();
}
// Update is called once per frame
void Update()
{

if (Input.GetKeyUp(KeyCode.LeftControl))
{
animation.Play(“Attacking”);
}

}
}

@pkoczewski

I doubt this is your full code, as I think this would show errors before even not working runtime.

Where is your anim field / variable defined - it is not defined in the class?

Also, in Update, you call animation.Play so where is that variable in your code? Shouldn’t you be calling anim?

Also - use code tags when posting, IMHO it is very hard to read code without proper formatting.

Thank you eses I will try.