So i wanted to make a ground checker but it didnt work .There is an error that i cant fix.
PlayerMovement2.cs(29,14): error CS8112: Local function ‘GroundCheck()’ must declare a body because it is not marked ‘static extern’.
and these are some warnings:
PlayerMovement2.cs(29,14): warning CS8321: The local function ‘GroundCheck’ is declared but never used
PlayerMovement2.cs(15,27): warning CS0414: The field ‘PlayerMovement2.isGrounded’ is assigned but its value is never used
Can someone help
This is my player movement with the ground check
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement2 : MonoBehaviour
{
Rigidbody2D rb;
[SerializeField] Transform groundCheckCollider;
[SerializeField] LayerMask groundLayer;
const float groundCheckRadius = 0.2f;
float horizontalValve;
bool facingRight = true;
public float speed = 1;
[SerializeField] bool isGrounded = false;
void Awake()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
horizontalValve = Input.GetAxisRaw("Horizontal");
}
void FixedUpdate()
{
void GroundCheck();
Move(horizontalValve);
}
void GroundCheck()
{
isGrounded = false;
Collider2D[] colliders = Physics2D.OverlapCircleAll(groundCheckCollider.position, groundCheckRadius, groundLayer);
if (colliders.Length > 0)
isGrounded = true;
}
void Move(float dir)
{
float xVal = dir * speed * 100 * Time.fixedDeltaTime;
Vector2 targetVelocity = new Vector2(xVal, rb.velocity.y);
rb.velocity = targetVelocity;
if (facingRight && dir < 0)
{
transform.localScale = new Vector3(-3, 3, 3);
facingRight = false;
}
else if (!facingRight && dir > 0)
{
transform.localScale = new Vector3(3, 3, 3);
facingRight = true;
}
}
}