Im making aplatformer and my when i try to make it so that the character flips on the x when i move left but for some reason its not working. this is my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed;
public float jumpForce;
private Rigidbody2D rb2d;
bool facingRight = true;
// Start is called before the first frame update
void Start()
{
rb2d = GetComponent<Rigidbody2D>();
}
public Animator animator;
void Update()
{
animator.SetFloat("Horizontal", Input.GetAxis("Horizontal"));
float moveInput = Input.GetAxisRaw("Horizontal");
Scale.position += new Vector3 (moveInput, 0, 0) * moveSpeed * Time.deltaTime;
if (Input.GetKeyDown(KeyCode.Space) && Mathf.Abs(rb2d.velocity.y) < 0.001f)
{
rb2d.AddForce(new Vector2 (0, jumpForce), ForceMode2D.Impulse);
}
if(inputHorizontal > 0 && !facingRight)
{
Flip();
}
else if(input.horizontal < 0 && facingRight)cale
{
Flip();
}
}
void Flip()
{
Vector3 currentScale = gameObject.transform.localScale;
currentScale.x *= -1;
gameObject.transform.localScale = currentScale;
facingRight = !facingRight;
}
}
sorry if this script is pasted wropng im new to unity
thankyou