Unexpected Symbol 'void'
I am attempting to make a first person character pick up an object via a tutorial by a man named Jimmy Vegas. This is the C# code that was given. I copied it directly but I am continuing to get 'Unexpected Symbol' errors. First it was the semicolon in line 1 so I deleted that. Next, it was the word 'void' in line 3, then 'Update', also in line 3. Eventually I was destroying most of the script. I am new to coding but I tried my best and failed to find the issue. Any and all help is appreciated and I thank you in advance.
A quick side note. I don't know how much it will affect things overall but the code was written in 2015 I believe.I realize this probably makes a huge difference but again I'm new to coding and am open to criticism.
Answer by Stratosome · Jul 15, 2018 at 02:44 AM
Hiya,
Alrighty, so, there are a couple issues there. The semicolon is a problem, but when you delete that, you will see other issues and such. So, the problem is that this code isn't inside of a class and it needs to be. I can't quite tell if "target" was supposed to be the name of this class, or if that was supposed to be a variable that you can reference in Unity's inspector window, but try to follow this format for Monobehaviour classes (a Monobehaviour is essentially a script that is part of an object that could be in a scene).
// Some script for a scene object
public class ExampleMonobehaviour : MonoBehaviour {
public GameObject target; // A public variable that will show up in Unity's inspector window
void Update() {
// ...
}
void OnMouseDown() {
// ...
}
void OnMouseUp() {
// ...
}
}
Your answer
Follow this Question
Related Questions
Error CS1525: Unexpected symbol 'void' 1 Answer
cannot be an iterator block because `void' is not an iterator interface type 1 Answer
Keyword 'void' cannot be used in this context, cant figure out what to do 1 Answer
Unexpected symbol `void' in class, struct, or interface member declaration 1 Answer
"void" error in SceneManager Script 1 Answer