I have recently created the following script
to make my character object move in either direction and also flip his sprite when moving left if facing right and visa versa
//variables are being set
public float maxspeed = 10f;
bool facingright = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate ()
{
float move = Input.GetAxis("horizantal");
UnityEngine.Rigidbody2D.velocity = new Vector2(move * maxspeed, UnityEngine.Rigidbody2D.velocity.y);
if (move > 0 && !facingright)
Flip();
else if (move < 0 && facingright)
Flip();
}
//flips the player when they're facing left
void Flip()
{
facingright = !facingright;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
However i get error CS0120 and I can’t figure out how to fix it.