CodeBlanks Logo Icon CodeBlanks

Summary - Animation

Reinforce animation usage with a summary task.

Putting the Animation System Together

In Unity's animation system, Animation Clips store animation data, while Animator Controllers manage states and transitions. Parameters define transition conditions. C# code controls the animation system by changing these parameters through methods such as SetTrigger(), SetBool(), and SetFloat().

// Clip → State
// State → Transition
// Parameter → Condition
// C# → Animator

Practice Manage Character Animations Together

Manage the character's damage and movement animations through an Animator component. Activate the takeDamage Trigger parameter in SetDamage. Pass the received speed to the moveSpeed Float parameter in SetMovement. Create parameters with these names in the Animator Controller.

Starter code

Player.cs
using UnityEngine;

public class AnimationManager : MonoBehaviour
{
    public Animator animator;

    // SetDamage ve SetMovement metotlarını buraya ekle
}

Sample solution

Player.cs
using UnityEngine;

public class AnimationManager : MonoBehaviour
{
    public Animator animator;

    public void SetDamage()
    {
        animator.SetTrigger("takeDamage");
    }

    public void SetMovement(float speed)
    {
        animator.SetFloat("moveSpeed", speed);
    }
}

Expected output

Hasar animasyonu tetiklendi
Hareket hızı güncellendi

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which approach is suitable for making a character enter a damage animation when it takes damage?

  • Delete the Animation Clip file
  • Close the Curve view
  • Rename the GameObject
  • Create a Trigger parameter in the Animator and activate it from code Correct answer

Explanation: A Trigger parameter can be activated from code to start the transition to a damage animation.

2 Start an Animation Transition

Question
Animator Controller'da tek seferlik bir olayla geçiş başlatmak için koddan ____ metodu çağrılır.
Answer
Animator Controller'da tek seferlik bir olayla geçiş başlatmak için koddan SetTrigger metodu çağrılır.

Explanation: SetTrigger() activates the corresponding Trigger parameter and can satisfy the transition condition.

3 Match the Animation Process

Term Meaning
Animation Clip hazırlama Creating the motion data to be played
State tanımlama Linking a clip to an Animator state
Condition belirleme Setting condition for a state change
Koddan parametre değiştirme Controlling transitions at runtime

All lessons in Intermediate