Search Unity

Animation Script

Discussion in 'Scripting' started by behdadsoft, Aug 28, 2012.

  1. behdadsoft

    behdadsoft

    Joined:
    Aug 25, 2012
    Posts:
    152
    Hello:D

    I Maked a character with animation (Walk Jump), But I Don't Know how can run this animations with Scripts. Please tell me how can I do it? I recently worked with this engine, and I'm going to make a game please help me to do this.

    THANKS A LOT
     
  2. fano_linux

    fano_linux

    Joined:
    Jan 1, 2012
    Posts:
    909
    Well then, i suggest you to take a look at this first: http://docs.unity3d.com/Documentation/ScriptReference/30_search.html?q=animation
    Take a look.

    When you feel you know scripting and unerstand the animation concept.

    Import your character to unity, split the animations, create a script to do the animation.play();, attach the script to your char, and there you go.
    It's not so simple, "like please unity play the animation"... but as soon you learn scripting and the concept will be really easy to do so.
     
  3. behdadsoft

    behdadsoft

    Joined:
    Aug 25, 2012
    Posts:
    152
    Thanks, I See This Document but I think it is too much to begin with.
    I know a little scripting but if you can offer a simpler way to understand the animation is much better.This file includes all forms of animation, and I still use the keyboard to use the Animation do not know.
     
  4. fano_linux

    fano_linux

    Joined:
    Jan 1, 2012
    Posts:
    909
    OK then, first search at youtube how to import your char and split the animations by the unity inspector. After that, put your char at scene and attach this script to the char.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. /// <Sumario>
    6. /// Stêffano de Moura
    7. /// 28/08/2012
    8. /// </Sumario>
    9. public class Animator : MonoBehaviour
    10. {
    11.     void Update()
    12.     {
    13.         //If the button is pressed
    14.         if (Input.GetButton("Fire1"))
    15.         {
    16.             //Fade in the animation
    17.             animation.CrossFade("YOUR_ANIMATION_NAME");
    18.         }
    19.         else
    20.         {
    21.             ///if not fade in other
    22.             animation.CrossFade("YOUR_ANOTHER_ANIMATION_NAME");
    23.         }
    24.     }
    25. }
    26.  
    27.  
    then hit play

    "Don't forget to change the animations name"
     
  5. behdadsoft

    behdadsoft

    Joined:
    Aug 25, 2012
    Posts:
    152
    Thanks, Can You give me Java Scripte?