Search Unity

HELP: "a namespace cannot directly contain members such as fields or methods"

Discussion in 'Scripting' started by ehowe420, Jan 21, 2019.

  1. ehowe420

    ehowe420

    Joined:
    Jan 21, 2019
    Posts:
    1
    Hey,
    On line 45, column 9, there is an error that I do not know how to fix. Can anyone help me? Thanks in advance. It is the line that says "return Physics.raycast"

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class CharacterMovement : MonoBehaviour
    7. {
    8.     public float speed = 5;
    9.     public float jumpPower = 4;
    10.     Rigidbody rb;
    11.     CapsuleCollider col;
    12.  
    13.     // Use this for intialization
    14.     void Start()
    15.     {
    16.         Cursor.lockState = CursorLockMode.Locked;
    17.         rb = GetComponent<Rigidbody>();
    18.         col = GetComponent<CapsuleCollider>();
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     void Update()
    23.     {
    24.         //Get the input value from the controllers
    25.         float Horizontal = Input.GetAxis("Horizontal") * speed;
    26.         float Vertical = Input.GetAxis("Vertical") * speed;
    27.         Horizontal *= Time.deltaTime;
    28.         Vertical *= Time.deltaTime;
    29.         //Translate our character via our inputs.
    30.         transform.Translate(Horizontal, 0, Vertical);
    31.  
    32.         if (isGrounded() && Input.GetButtonDown("Jump"))
    33.         {
    34.             //Add upward force to the rigid body when we press jump.
    35.             rb.AddForce(Vector3.up * jumpPower, ForceMode.Impulse);
    36.         }
    37.  
    38.         if (Input.GetKeyDown("escape"))
    39.             Cursor.lockState = CursorLockMode.None;
    40.         {
    41.  
    42.          private bool isGrounded();
    43.         }
    44.         //Test that we are grounded by drawing an invisible line (raycast)
    45.         //If this hits a solid object e.g. floor then we are grounded.
    46.         return Physics.Raycast(transform.position, Vector3.down, col.bounds.extents.y + 0.1f);
    47.     }
    48. }
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    you hae written the method called 'isGrounded' inside the body of the Update method
    Check your bracketing, and your line ends ( ; )