Search Unity

Idle and Run parameter

Discussion in 'Animation' started by wafolus, Dec 11, 2013.

  1. wafolus

    wafolus

    Joined:
    Dec 11, 2013
    Posts:
    2
    $unity2.png

    Hello guys, i have a problem with my parameter. Why doesn't my "speed" parameter work for my idle and run?
    Perhaps i lack something with my codes?


    Here's my code:

    using UnityEngine;
    using System.Collections;

    public class characterMove : MonoBehaviour {

    private float playerSpeed = 5.0f;
    public GameObject target;

    public bool jump = false;
    public float jumpForce = 10f;

    private Transform groundCheck;
    private bool grounded = false;

    void Awake()
    {
    groundCheck = target.transform.Find("groundCheck");
    }

    // Use this for initialization
    void Start ()
    {

    }

    // Update is called once per frame
    void Update ()
    {
    grounded = Physics2D.Linecast(target.transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("ground"));
    }//update

    void FixedUpdate ()
    {
    if(jump){
    target.rigidbody2D.AddForce(new Vector2(0f,250f));
    jump = false;
    }
    }

    void OnGUI ()
    {
    if(GUI.RepeatButton(new Rect(0,0,Screen.width,Screen.height/2),"Jump") grounded)
    {
    jump = true;
    }

    if(GUI.RepeatButton(new Rect(0,Screen.height/2,Screen.width/2,Screen.height/2),"L"))
    {
    target.transform.Translate(Vector2.right * playerSpeed * Time.deltaTime);
    target.transform.rotation = Quaternion.AngleAxis(180, Vector3.up);
    }
    if(GUI.RepeatButton(new Rect(Screen.width/2,Screen.height/2,Screen.width/2,Screen.height/2),"R"))
    {
    target.transform.Translate(Vector2.right * playerSpeed * Time.deltaTime);
    target.transform.rotation = Quaternion.AngleAxis(0, Vector3.up);
    }
    }//GUI
    } //class
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Yeah, I don't see anything in your code that actually sets the speed. I would expect to see something like:

    Code (csharp):
    1. animator.SetFloat("speed", Input.GetAxis("Horizontal"))
    or whatever other speed you want to set.

    HTH,
    - Joe