Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Recieving a error with void Update

Discussion in 'Scripting' started by DatAlles19, Jul 29, 2020.

  1. DatAlles19

    DatAlles19

    Joined:
    May 14, 2020
    Posts:
    4
    I went through my code and the error is only going away when I mark out void Update()
    also with void Start()
    I receive an error in unity saying: A name space cannot contain members such as a field or methods.
     
    Last edited: Jul 29, 2020
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    10,004
    Code (CSharp):
    1. void Update()
    And maybe more in the code you haven't shared with us.
     
    DatAlles19 likes this.
  3. DatAlles19

    DatAlles19

    Joined:
    May 14, 2020
    Posts:
    4
    Code (CSharp):
    1.   void Start()
    2.    {
    3.       var startingPosition = transform.position;
    4.    }  
    5.        
    6.  
    7.  
    8.     // Update is called once per frame
    9.     void Update()
    10.     {
    11.         isGrounded = Physics.CheckSphere(groundcheck.position, groundDistance, groundMask);
    12.         islava = Physics.CheckSphere(groundcheck.position, lavaDistance, lavaMask);
    13.  
    14.         if (isGrounded && velocity.y < 0)
    15.         {
    16.             velocity.y = -1f;
    17.         }
    18.  
    19.        if (islava = true)
    20.        {
    21.           transform.position = startingPosition.transform.position;
    22.        }
    23.  
    this is where the error could be
     
  4. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    10,004
    No, the error could be anywhere, since "something namespace". You probably don't have a class, or defined some member variables outside of it.

    You really need to work on your problem-explanation skills. Paste all of your code from the file and paste all the error you get. Otherwise our ability to help is severely limited. Don't forget, we aren't there with you, we didn't see anything you have seen, we don't know anything about your code and project, only this, what you have shared, which is next to nothing.
     
    DatAlles19 likes this.
  5. DatAlles19

    DatAlles19

    Joined:
    May 14, 2020
    Posts:
    4
    here
     
  6. DatAlles19

    DatAlles19

    Joined:
    May 14, 2020
    Posts:
    4
    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.Security.Cryptography;
    5. using UnityEngine;
    6.  
    7. public class playermovement : MonoBehaviour
    8. {
    9.     public CharacterController controller;
    10.  
    11.     public float speed = 12f;
    12.     public float gravity = -9.81f;
    13.  
    14.     public Transform groundcheck;
    15.     public float groundDistance = 0.4f;
    16.     public LayerMask groundMask;
    17.  
    18.     public float lavaDistance = 0.4f;
    19.     public LayerMask lavaMask;
    20.  
    21.     public float jumpHeight = 2f;
    22.  
    23.     Vector3 velocity;
    24.     bool isGrounded;
    25.     bool islava;
    26.  
    27.    public float startpos;
    28.  
    29. }
    30.     // Start is called before the first frame update
    31.    void Start()
    32.    {
    33.       var startingPosition = transform.position;
    34.    }  
    35.        
    36.  
    37.  
    38.     // Update is called once per frame
    39.     void Update()
    40.     {
    41.         isGrounded = Physics.CheckSphere(groundcheck.position, groundDistance, groundMask);
    42.         islava = Physics.CheckSphere(groundcheck.position, lavaDistance, lavaMask);
    43.  
    44.         if (isGrounded && velocity.y < 0)
    45.         {
    46.             velocity.y = -1f;
    47.         }
    48.  
    49.        if (islava = true)
    50.        {
    51.           transform.position = startingPosition.transform.position;
    52.        }
    53.  
    54.  
    55.         float x = Input.GetAxis("Horizontal");
    56.         float z = Input.GetAxis("Vertical");
    57.  
    58.         Vector3 move = transform.right * x + transform.forward * z;
    59.  
    60.         controller.Move(move * speed * Time.deltaTime);
    61.  
    62.         if (Input.GetButtonDown("Jump")  && isGrounded)
    63.         {
    64.             velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
    65.         }
    66.  
    67.         velocity.y += gravity * Time.deltaTime;
    68.         controller.Move(velocity * Time.deltaTime);
    69.  
    70.     }
    71.  
     
  7. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    10,004
    @DatAlles19 in your above example on your line 29 you have the closing }. Move it to the end of the file (line 71 or so).