Hello.
I have written a 2d movement script but my character won’t move.
However, my character does play the animations I assigned to it, when I press D he does the walking animation facing to the right and if I press A he does the walking animation facing to the left but I can’t get my character to move. Can someone figure out what’s wrong with my code? It’s written in c# btw
I appreciate your help.
using UnityEngine;
using System.Collections;
public class Movescript : MonoBehaviour
{
public float maxSpeed = 10f;
bool facingRight = true;
Animator anim;
void Start ()
{
anim = GetComponent<Animator>();
}
void Update ()
{
float move = Input.GetAxis ("Horizontal");
anim.SetFloat ("Speed", Mathf.Abs (move));
rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);
if (move > 0 !facingRight)
Flip ();
else if (move < 0 facingRight)
Flip ();
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}