help on ground check

I tryed to add ground check plz fix this script:

//--------------------------------------------------Gamer-Peebs-----------------------------------------
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class playerMovment : MonoBehaviour
{

    public CharacterController2D controller;

    public float runSpeed = 40f;

    float horizontalMove = 0f;

    bool jump = false;
    bool chouch = false;
  
    public  CircleCollider2D foot;


    void Update ()
    {
        horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;

        if (ongrawnd() && Input.GetButtonDown("Jump"))
        {
            jump = true;
            ongrawnd = false;
        }

        if (Input.GetButtonDown("chouch"))
        {
            chouch = true;
        } else if (Input.GetButtonUp("chouch"))
        {
            chouch = false;
        }
    }

  
    void FixedUpdate ()
    {
        public bool ongrawnd()
        {
            float extraHeightText = .01f;
            RaycastHit2D raycastHit = Physics2D.Raycast(boxCollider2d.bounds.center, Vector2.down, boxCollider2d.boundsextents.y + extraHeightText);
            Color rayColor;
            if (raycastHit.collider != null)
            {
                rayColor = rayColor.green;
            }
            else
            {
                rayColor = rayColor.red;
            }
            Debug.DrawRay(boxCollider2d.bounds.center, Vector2.down * (boxCollider2d.boundsextents.y + extraHeightText);)
        return raycastHit.collider != null;
        }
      

    controller.Move(horizontalMove * Time.fixedDeltaTime, chouch, jump);
        jump = false;
        ongrawnd = true;
    }
   
}

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

How to understand compiler and other errors and even fix them yourself:

Beyond that, to help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run?
  • what are the values of the variables involved? Are they initialized?

Knowing this information will help you reason about the behavior you are seeing.

1 Like

first of all, you basically did this

void Update()
{
    void FixedUpdate()
}

if you still does not understand, reply me.

no I did not this is void Update:

  void Update ()
    {
        horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
        if (ongrawnd() && Input.GetButtonDown("Jump"))
        {
            jump = true;
            ongrawnd = false;
        }
        if (Input.GetButtonDown("chouch"))
        {
            chouch = true;
        } else if (Input.GetButtonUp("chouch"))
        {
            chouch = false;
        }
    }

some of my errors:
Assets\playerMovment.cs(66,1): error CS1022: Type or namespace definition, or end-of-file expected
Assets\playerMovment.cs(63,18): error CS1519: Invalid token ‘=’ in class, struct, or interface member declaration
Assets\playerMovment.cs(62,14): error CS1519: Invalid token ‘=’ in class, struct, or interface member declaration
Assets\playerMovment.cs(61,71): error CS1519: Invalid token ‘)’ in class, struct, or interface member declaration
Assets\playerMovment.cs(61,42): error CS1026: ) expected
Assets\playerMovment.cs(61,42): error CS8124: Tuple must contain at least two elements.
Assets\playerMovment.cs(61,20): error CS1519: Invalid token ‘(’ in class, struct, or interface member declaration
Assets\playerMovment.cs(56,121): error CS1513: } expected
Assets\playerMovment.cs(56,120): error CS1026: ) expected
Assets\playerMovment.cs(43,9): error CS0106: The modifier ‘public’ is not valid for this item

put OnGround Field on Class, not FixedUpdate

help me i am new and confused

Pointless, lazy thread. Read the rules before posting again.