I'm working on a C#7.0 coding project for Unity3D, and am building a script for doors. This comes directly from a project in the book Unity3.X Game Development Essentials which was recommended to me by a gaming professor. I'm learning code on my own, so I'm at the mercy of any updates. For some reason, the code expects an identifier but I'm unsure what identifier it could possibly want. On a level of skill with coding, I'm right above a snail without a shell, so any advice would be greatly appreciated. At one point in time, this code clearly worked because it was published in a book and was recommended by advanced members of staff. I think the code has been updated though. Any thoughts? Any advice? Thanks so much!
-
1It looks to me like the code in the screenshot is an assignment and you're supposed to fill in the blanks to make the code work. The clues are in the code for you to fix – Wayne Phipps Nov 26 '18 at 21:21
-
2Post your code not screenshot of it. If you have an error, post the error too. The screenshot shows that the `Door` function is missing variable names for its parameters. It should be `public void Door(AudioClip doorOpenSound, bool openCheck, string animName)` **not** `public void Door(AudioClip, bool, string animName)`. Notice how the AudioClip and bool variable names are missing..... – Programmer Nov 26 '18 at 21:24
-
Yes!!! Thank you so so so much to both of you. I really appreciate all the help I can get. <3 Now I see where I went wrong. I will make sure to watch out for this in future. You guys are the best!!! – L. Dostal Nov 26 '18 at 21:30
1 Answers
Well, the problem is at a line which defines your method Door
.
A method may take input parameters from its caller. Those parameters are variables, available from within the method. Variables are pointers to a memory and their primary goal is to keep information. A variable in C# must always have a type, without a type, variable is meaningless. For example, your variable may be a string (and contain things like "word", "sentence with multiple words" and so on), or integer (1, 5, 1000, -256 and so on), and many many other types.
Your method definition, I believe, is supposed to have three parameters. In C#, when defining a parameter (or a variable), you first write its type, and then its name. Like this: string someVar
, or this: int someOtherVar
.
In your case, you're missing those names. Your method definition containts only types, separated by comma, but no names. Name your parameters and the compilation errors will disappear.
For example, like this:
public void Door(AudioClip doorOpenSound, bool openCheck, string animName)

- 8,944
- 8
- 43
- 90
-
Thank you so much! I'm almost in tears I'm so happy. I felt like the problem was staring me in the face for ages, and now I see where I went wrong. You are the best of the best! <3 – L. Dostal Nov 26 '18 at 21:31