Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

easy walk animaton script help!

Discussion in 'Scripting' started by lionbear, May 13, 2013.

  1. lionbear

    lionbear

    Joined:
    Mar 22, 2011
    Posts:
    12
    i have been trying to make an easy walk animation script. like final fantasy or most of the old school rpgs. or at least close to it.
    Code (csharp):
    1.  
    2.     function Update () {
    3.         if(Input.GetButtonDown("a")){
    4.             animation.Play("walk");
    5.         }
    6.         else if(Input.GetButtonUp("d")){
    7.             animation.Stop("walk");
    8.         }
    9.         else if(Input.GetButtonLeft("w")){
    10.             animation.Stop("walk");
    11.         }
    12.         else if(Input.GetButtonRight("s")){
    13.             animation.Stop("walk");
    14.         }
    15.     }
    16.  
    i have a simple walk animation. and my character mesh. but i am not sure how to add the script to it to make him animate and move?

    my walk animation is called "walk" and my character mesh is "hero" if that helps?

    update: here is the console error i get if i add my script to my character mesh.

    UnityException: Input Button l is not setup.
    To change the input settings use: Edit -> Project Settings -> Input
    Walk.Update () (at Assets/models/hero/script/Walk.js:2)


    update: i found the problem i was adding my FBX to my OBJ modal all i needed was the FBX file what a noob i am lol! thinks guys for all your help!
     
    Last edited: May 14, 2013
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    theres no such fucntion as

    Input.GetButtonLeft
     
  3. lionbear

    lionbear

    Joined:
    Mar 22, 2011
    Posts:
    12
    if there is up and down. why not left and right? or are you saying pushing the button down?
     
    Last edited: May 14, 2013
  4. GBCFraser

    GBCFraser

    Joined:
    Apr 11, 2013
    Posts:
    94
    lionbear,
    Its pushing the button down and up.
    Button gets the input from the input manager.
    In the input manager you can put references to keycodes.
    The is a labour saving device if you want port you game to different platforms, or you want to change the keys, or have the user change the keys in game.
     
  5. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    and in case there's a follow up "why?", think of a game like worms; when space is pressed down the force builds up behind the shot, when space is released (buttonUp) the shot is fired :)