Recieving a error with void Update

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.

void Update()

And maybe more in the code you haven’t shared with us.

1 Like
  void Start()
   {
      var startingPosition = transform.position;
   }  
       


    // Update is called once per frame
    void Update()
    {
        isGrounded = Physics.CheckSphere(groundcheck.position, groundDistance, groundMask);
        islava = Physics.CheckSphere(groundcheck.position, lavaDistance, lavaMask);

        if (isGrounded && velocity.y < 0)
        {
            velocity.y = -1f;
        }

       if (islava = true)
       {
          transform.position = startingPosition.transform.position;
       }

this is where the error could be

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.

1 Like

here

using System;
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;

public class playermovement : MonoBehaviour
{
    public CharacterController controller;

    public float speed = 12f;
    public float gravity = -9.81f;

    public Transform groundcheck;
    public float groundDistance = 0.4f;
    public LayerMask groundMask;

    public float lavaDistance = 0.4f;
    public LayerMask lavaMask;

    public float jumpHeight = 2f;

    Vector3 velocity;
    bool isGrounded;
    bool islava;

   public float startpos;

}
    // Start is called before the first frame update
   void Start()
   {
      var startingPosition = transform.position;
   }  
       


    // Update is called once per frame
    void Update()
    {
        isGrounded = Physics.CheckSphere(groundcheck.position, groundDistance, groundMask);
        islava = Physics.CheckSphere(groundcheck.position, lavaDistance, lavaMask);

        if (isGrounded && velocity.y < 0)
        {
            velocity.y = -1f;
        }

       if (islava = true)
       {
          transform.position = startingPosition.transform.position;
       }


        float x = Input.GetAxis("Horizontal");
        float z = Input.GetAxis("Vertical");

        Vector3 move = transform.right * x + transform.forward * z;

        controller.Move(move * speed * Time.deltaTime);

        if (Input.GetButtonDown("Jump")  && isGrounded)
        {
            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
        }

        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);

    }

@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).