Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Skeleton animation in Unity [Chapter 2]

    • 0
    • 8
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.09k
    Comment on it

    Blog 2 :- Skeleton animation in Unity

    Hey Guys, this blog is part of a series " Skeleton animation in Unity". In this i'll try to explain "how to play animations of spine objects in Unity".

    For this make sure you have "spine-unity.unitypackage" plugin in your project.

    It is assumed that you have already Instatntitated your spine object in Game Scene.

    Step1: Create a script as "PlayerAnimations.cs" an apply it on Spine Character.

    Step 2: Use following code :

    We will play animations on Key press

    using UnityEngine;
    using System.Collections;public class PlayAnimation : MonoBehaviour

     {
    
    //assign all spine animations of game character to string variables
    
    stringidleAnimation="1IdleAnimation";
    
    stringrunAnimation="2RunningAnimation";
    stringjumpAnimation="3JumpingAnimation";
    stringattackAnimation="4Attack";
    
    SkeletonAnimationskeletonAnimation; //skeleton animation variable will used to call methods of SkeletonAnimation
    
    voidStart()
    
    {
    
    //assign skeletonAnimation
    
    skeletonAnimation=GetComponent<SkeletonAnimation>();
    
    SetAnimation(idleAnimation,true);
    
    }
    
    //Function to set animations to spine character or we can set animation directly without making this function.
    
    voidSetAnimation(stringanim,boolloop)
    {
    skeletonAnimation.state.SetAnimation(0,anim,loop);
    
    }
    
    voidUpdate()
    {
    if(Input.GetKey(KeyCode.A))
    SetAnimation(runAnimation,false);
    
     if(Input.GetKey(KeyCode.W))
    SetAnimation(jumpAnimation,false);
     if(Input.GetKey(KeyCode.Space))
    SetAnimation(attackAnimation,false);
     if(Input.GetKey(KeyCode.I))
    SetAnimation(idleAnimation,false);
    
     }
    
    }
    
    

    Now you can play animations on key press of spine object.

    Comment for suggestions.

    Thank You !

     

     

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: