Sunday, December 15, 2013

Importing Mesh and Animation from 3D Studio Max to Unity3D

In past some post I tried to show how we can perform 2D animation and collision detection.

In this post I am will show I we can import 3D mesh with animation created from 3D studio max to Unity3D and animate the same.

So lets start, I created a sample mesh with animation with 3D Studio max.


We need to export it using FBX file format, which we can easily import in Unity3D.


To import it, you can drop the created FXB format file to Asset folder in Unity3D. Once you import it click imported mesh to display its property in Inspector window. In Inspector window click on Rig tab and set animation type to Legacy.

This is required else animation will not play and you will get error "Animation needs to be marked as Legacy"




Now we can use this mesh and perform animation, you can also change its property like play automatically or loop animation.


Now lets add a script, which make model jump when pressing some button.


And here is script.
using UnityEngine;
using System.Collections;

public class JumpAnimation : MonoBehaviour {

 // Update is called once per frame
 void Update () {
  if(  Input.anyKeyDown ) {
   animation.Play("Jump");
  }
 }
}

So now its ready,if you press any button now, it should jump. Here is video how it looks.

 

1 comment: