The name Flip and Horizontal does not exsist in the current context. pls help

How can I fix that they are existing?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour {

public float WallDownForce;
public float speed;
public float jumpForce;
private float moveInput;

private Rigidbody2D rb;

private bool facingRight;

private bool isGrounded;
public Transform groundCheck;
public float checkRadius;
public LayerMask whatIsGround;

private bool onWall;
public Transform wallCheck;
public float WallCheckRadius;
public LayerMask whatIsWall;

private int extraJumps;
public int extraJumpsValue;

// Start is called before the first frame update
void Start() {
extraJumps = extraJumpsValue;
rb = GetComponent();
facingRight = true;
}

void FixedUpdate() {

Flip(Horizontal);

onWall = Physics2D.OverlapCircle(wallCheck.position, WallCheckRadius, whatIsWall);
isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
moveInput = Input.GetAxis(“Horizontal”);
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
}
void Update(){

if(isGrounded == true){
extraJumps = 1;
}
if(onWall == true){
extraJumps = 1;
}
if(Input.GetKeyDown(KeyCode.Space) && extraJumps > 0){
rb.velocity = Vector2.up * jumpForce;
extraJumps–;
}else if(Input.GetKeyDown(KeyCode.UpArrow) && extraJumps == 0 && isGrounded == true){
rb.velocity = Vector2.up * jumpForce;

if(Input.GetKeyDown(KeyCode.Space) && extraJumps > 0){
rb.velocity = Vector2.up * jumpForce;
extraJumps–;
}else if(Input.GetKeyDown(KeyCode.UpArrow) && extraJumps == 0 && onWall == true){
rb.velocity = Vector2.down * WallDownForce;
}
}
void Flip(float Horizontal)
{

if (Horizontal > 0 && !facingRight || Horizontal < 0 && facingRight)
{
facingRight = !facingRight;

Vector3 theScale = transform.localScale;

theScale.x *= -1;

transform.localScale = theScale;
}

}
}
}

https://discussions.unity.com/t/481379

1 Like

Also, copy & paste the actual error, including line number.

Check your parenthesis. This is almost always caused by having too many and in the wrong place.

I believe it’s this line, Horizontal is not defined

Flip(Horizontal);

Try Flip(0);

and go from there. But please use code tags, I’m not sure but I believe Flip is improperly defined inside another method.

Yes. He’s defined it inside of the Update() method. Below is the code with the function moved outside of it.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{

    public float WallDownForce;
    public float speed;
    public float jumpForce;
    private float moveInput;

    private Rigidbody2D rb;

    private bool facingRight;

    private bool isGrounded;
    public Transform groundCheck;
    public float checkRadius;
    public LayerMask whatIsGround;

    private bool onWall;
    public Transform wallCheck;
    public float WallCheckRadius;
    public LayerMask whatIsWall;

    private int extraJumps;
    public int extraJumpsValue;

    // Start is called before the first frame update
    void Start()
    {
        extraJumps = extraJumpsValue;
        rb = GetComponent<Rigidbody2D>();
        facingRight = true;
    }

    void FixedUpdate()
    {

        Flip(Horizontal);

        onWall = Physics2D.OverlapCircle(wallCheck.position, WallCheckRadius, whatIsWall);
        isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
        moveInput = Input.GetAxis("Horizontal");
        rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
    }
    void Update()
    {

        if (isGrounded == true)
        {
            extraJumps = 1;
        }
        if (onWall == true)
        {
            extraJumps = 1;
        }
        if (Input.GetKeyDown(KeyCode.Space) && extraJumps > 0)
        {
            rb.velocity = Vector2.up * jumpForce;
            extraJumps--;
        }
        else if (Input.GetKeyDown(KeyCode.UpArrow) && extraJumps == 0 && isGrounded == true)
        {
            rb.velocity = Vector2.up * jumpForce;

            if (Input.GetKeyDown(KeyCode.Space) && extraJumps > 0)
            {
                rb.velocity = Vector2.up * jumpForce;
                extraJumps--;
            }
            else if (Input.GetKeyDown(KeyCode.UpArrow) && extraJumps == 0 && onWall == true)
            {
                rb.velocity = Vector2.down * WallDownForce;
            }
        }
    }
    void Flip(float Horizontal)
    {

        if (Horizontal > 0 && !facingRight || Horizontal < 0 && facingRight)
        {
            facingRight = !facingRight;

            Vector3 theScale = transform.localScale;

            theScale.x *= -1;

            transform.localScale = theScale;
        }

    }
}