Hello guys, i am a beginner in unity2d, im following a tutorial on youtube, but i came across an error on the argument ‘moveDir’ i get the message “Cannot convert type UnityEngine.Vector2’ expression to type float’”, please help me to solve this error, all i want is to make animation when the character moves… THANK YOU
public int moveSpeed;
public int jumpheight;
private Animator _anim;
Rigidbody2D rb2d;
// Use this for initialization
void Start () {
rb2d = GetComponent<Rigidbody2D>();
_anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
Vector2 moveDir = new Vector2(Input.GetAxisRaw("Horizontal")* moveSpeed, rb2d.velocity.y);
_anim.SetFloat("Speed", moveDir);
rb2d.velocity = moveDir;
if (Input.GetAxisRaw("Horizontal") == 1)
{
transform.localScale = new Vector3(1, 1, 1);
}
else if (Input.GetAxisRaw("Horizontal") == -1)
{
transform.localScale = new Vector3(-1, 1, 1);
}
if (Input.GetKeyDown(KeyCode.Space))
{
rb2d.AddForce(new Vector2(0, jumpheight));
}