- Home /
Question by
TehKingPenguin · May 24, 2015 at 02:42 PM ·
platformer
I am trying to make a 2D game and this is my movement script , I have triple checked my script and I cannot find the problem! This is my error >> Parameter 'speed' does not exist.
using UnityEngine; using System.Collections;
public class Player : MonoBehaviour {
public float maxSpeed = 6;
public float speed = 50f;
public float jumpPower = 150f;
public bool grounded;
private Rigidbody2D rb2d;
private Animator anim;
void Start ()
{
rb2d = gameObject.GetComponent<Rigidbody2D>();
anim = gameObject.GetComponent<Animator>();
}
void Update ()
{
anim.SetBool("Grounded",grounded);
anim.SetFloat ("speed", Mathf.Abs(Input.GetAxis("Horizontal")));
if (Input.GetAxis ("Horizontal") < -0.1f)
{
transform.localScale = new Vector3(-1, 1 ,1);
}
if (Input.GetAxis ("Horizontal") > 0.1f)
{
transform.localScale = new Vector3(1, 1 ,1);
}
}
void FixedUpdate ()
{
float h = Input.GetAxis ("Horizontal");
//moving player
rb2d.AddForce((Vector2.right * speed) * h);
//limits players speed
if (rb2d.velocity.x > maxSpeed)
{
rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y);
}
if (rb2d.velocity.x < -maxSpeed)
{
rb2d.velocity = new Vector2(-maxSpeed, rb2d.velocity.y);
}
}
}
Comment
Answer by SterlingSoftworks · May 25, 2015 at 06:40 PM
Easy fix.. Or so I'm assuming..
In your code:
void Update ()
{
anim.SetBool("Grounded",grounded);
anim.SetFloat ("speed", Mathf.Abs(Input.GetAxis("Horizontal")));
if (Input.GetAxis ("Horizontal") < -0.1f)
{
transform.localScale = new Vector3(-1, 1 ,1);
}
if (Input.GetAxis ("Horizontal") > 0.1f)
{
transform.localScale = new Vector3(1, 1 ,1);
}
}
Where you've put anim.SetFloat ("speed", Mathf.Abs(Input.GetAxis("Horizontal")));
I'm going to assume the parameter you've set up in the Animator is "Speed" not "speed"..
Your answer
![](https://koobas.hobune.stream/wayback/20220613200216im_/https://answers.unity.com/themes/thub/images/avi.jpg)