Unity Basic Animation (generic or default)

smallarrows.GIF

Tutorial to create an animation in Unity from scratch.

Add Animation to Objects in Unity

Create a GameObject->3D Object->Cube, or use any object in your scene.


Top menu bar  Assets->Create->Animation Controller re-name it.

Drag the Animation Controller onto your model.

Select the model, Select Window->Animation->Animation  (This brings up a timeline.)
     Select Create, name the animation

     Select Add Property
          Choose Transform->Position +   (This adds 2 keyframes)
               Open the down arrow unity_down_arrow_hierarchy to see the XYZ channels and values

          Change the time on the Timeline
          Move the Cube
          Click the Add keyframe button

Play the Game to see the animation.

Select Curves at the bottom of the Timeline window to manipulate acceleration between keys.

Close the Timeline window when you are through.

unity_basic_anim



Import Maya Animation Channels  (Default Animator)

Save your Maya file with animation into your Assets folder.

Select the Maya file from the
Assets folder:
     Under Rig leave the Animation Type Generic.
     Under Animation
          Change
Wrap Mode to Loop, in two sections.
          Select Loop Time

Drag your Maya file into your
Hierarchy.


Top menu bar  Assets->Create->Animation Controller re-name it.

Drag the Animation Controller onto your Maya file in the Hierarchy.

From Assets, double click the
Animation Controller, this brings up the Animator window.

From Assets, open the small arrow to reveal the contents of your Maya file in the Project window unity_asset_arrow

Drag Take 001 into the Animator window

unity_drag_take001_controller



Randomize the time and speed for multiple animations.
Written by Alex Rickett UCLA Game Lab
Apply this script to any animated object, Legacy or Default.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RandomlyPerturbAnimation : MonoBehaviour
{
    public float speedRandomizationAmount = .05f;
    IEnumerator Start()
    {
        yield return null;
        yield return null;
        yield return null;
        Animator animator = this.GetComponent<Animator>();
        if (animator != null)
        {
            animator.speed = Random.Range(1 - speedRandomizationAmount, 1 + speedRandomizationAmount);
            animator.Play(animator.GetAnimatorTransitionInfo(0).nameHash, 0, Random.Range(0f, 1f));
           
        }

        Animation animation = this.GetComponent<Animation>();
        if (animation != null)
        {

            animation[animation.clip.name].speed = Random.Range(1 - speedRandomizationAmount, 1 + speedRandomizationAmount);
            animation[animation.clip.name].normalizedTime = Random.Range(0f, 1f);
        }
        //yield return new WaitForSeconds(0, .2f);
    }

}