Search Unity

Bug Help me fix error plz the name does not exist in corrent context in the console

Discussion in 'Visual Scripting' started by hassanzeeshan6232, Jul 1, 2022.

  1. hassanzeeshan6232

    hassanzeeshan6232

    Joined:
    Jul 19, 2021
    Posts:
    4
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class NewBehaviourScript : MonoBehaviour
    6. {
    7.     public CharacterController controller;
    8.  
    9.     [Header("Movement")]
    10.     public float speed = 1f;
    11.     public float gravity = -9.10f;
    12.     public float jumpHeight = 1f;
    13.  
    14.     [Header("Ground Check")]
    15.     public Transform ground_check;
    16.     public float ground_distance = 0.4f;
    17.     public LayerMask ground_mask;
    18.  
    19.  
    20.     Vector3 velocity;
    21.     bool isGround;
    22.  
    23.     // Start is called before the first frame update
    24.     void Start()
    25.     {
    26.        
    27.     }
    28.  
    29.     // Update is called once per frame
    30.     void Update()
    31.     {
    32.         isGrounded = Physics.CheckSphere(ground_check.position, ground_distance, ground_mask);
    33.  
    34.         if(isGrounded && velocity.y < 0)
    35.         {
    36.             velocity.y = -2f;
    37.         }
    38.  
    39.         float z = input.GetAxis("Horizontal");
    40.         float x = input.GetAxis("Verticle");
    41.  
    42.         Vector3 move = transform.right * x + transform.forward * z;
    43.  
    44.         controller.Move(move * speed * Time.deltaTime);
    45.  
    46.         if (input.GetButtonDown("Jump") && isGrounded)
    47.         {
    48.             velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
    49.  
    50.         }
    51.  
    52.         velocity.y += gravity * Time.deltaTime;
    53.  
    54.         controller.Move(velocity * Time.deltaTime);
    55.  
    56.     }
    57. }
    58.  
    its a code i wrote by following a tutorial so he didnt got any errors but i did how?

    the errors i got was only The name 'isGrounded' does not exist in the current context.
    and same more errors excpet for isGrounded its another word

    HELP?
     
  2. munchmo

    munchmo

    Joined:
    May 20, 2019
    Posts:
    85
    I believe you may have posted this to the wrong forum. I'm certain a mod will come along shortly and move this to the right place.

    But good news! Your issue is at the very top, line 21, you are declaring a bool isGround but I believe it should be isGrouneded
     
  3. hassanzeeshan6232

    hassanzeeshan6232

    Joined:
    Jul 19, 2021
    Posts:
    4
    Bro but the guy i followed the tutorial of did write isGround
    he didnt wrote isGrounded
    He wrote isGrounded further in the next lines.
     
  4. hassanzeeshan6232

    hassanzeeshan6232

    Joined:
    Jul 19, 2021
    Posts:
    4
    Thanks brother it worked but the same error occurs in another word intedad of isGrounded, input

    the name input does not exist in current context

    can u check my code help me with th e solution
     
  5. munchmo

    munchmo

    Joined:
    May 20, 2019
    Posts:
    85
    Input should be Capitalized.