type or namespace definition or end-of-file expected in unity 2d

I am trying to make a game for me and my friends and I want npc to talk when I press a button,
for now, I didn’t make enabling the button when you get near but if you know that please help me with that too. Anyways, this is the code

using UnityEngine;
using System.Collections;

public class disre : MonoBehaviour
{
    public Renderer rend;

    void Start()
    {
        rend = GetComponent<Renderer>();
        rend.enabled = false;
    }

    // Toggle the Object's visibility each second.
    void Update()
    {
        // Find out whether current second is odd or even
        bool oddeven = Mathf.FloorToInt(Time.time) % 2 == 0;

        // Enable renderer accordingly
        rend.enabled = actionE;
       
        void onClick();
      if (lastButtonPressed == E)
      {
          //do actionE
      }
            
      }
    }
}

Not sure what you’re trying to do on line 23? If you’re trying to define another function, you want to get rid of the semicolon at the end of the line, and have a closing curly brace } above it to indicate the end of the Update function, and you may have too many closing curly braces at the end of the file.

And on line 24 you seem to be trying to use a variable that hasn’t been declared anywhere, so that may be giving you an error as well.

In general, it’s a good idea to paste the exact error message, including line numbers (if any).

1 Like

the error is gone but there is one problem, this code won’t work, there are too many errors,
and I know why; it’s because I tried to stick 2 different codes together with duct tape
I am gonna delete this post and make another post about the textbox.
Edit:turns out I cant delete posts

If there are a lot of errors, it’s often a misplaced curly brace, which causes a snowball effect for everything after that. Check those structures first.