Inspector does not show a box for public variable


I am now 1 minute in the video and I am completely stuck. I wanted to, like in the video, create a public instance player of the class Player. However after adding public Player player; It simply gives an error message:

Assets/Scripts/Ball.cs(7,9): error CS0246: The type or namespace name `Player’ could not be found. Are you missing an assembly reference?

[In the video they use paddle, but this doesn’t work either]

This wouldn’t be bad, if I had a box in the inspector of my ball object where I could drag my player object into (like in the video). But this box simply never appears.

I am using Unity 5.6.1f1

I added a zip of my project and some print screens. If anybody knows what is up, please help me.
(ps: the zip is an export file. If you open a new project you can import it as custom package. I am not sure if that is the easiest way to share it?)

Blockbreaker (3.2 MB)

1 Like

Okay, I took a break and found out what was wrong after. I answer my own post so that if others run in the same problem they can find the answer.

I was silly enough to NOT name my script attached to my Player object “Player” and instead thought to be clever and name it Movement. Hence my public class didn’t exist. Renaming the script attached to my player object (paddle) did the trick!

Whaha, man… I sometimes wonder if it is just me or whether everyone has these kind of problems… XD


Thanks for posting your answer. This is one of the biggest issues I have with this and many other programming courses (here and elsewhere). Many programmers love to name everything the same name, so confusion is inevitable. You’re certainly not silly, nor alone! :slight_smile:

I add “scr_” to the name of all my scripts, “img_” to my sprites, etc… I wish they’d do something similar since knowing what is being referenced would make the code self descriptive and how the syntax is being constructed (very important IMHO). i.e. if they would’ve used “public scr_Paddle paddle;” it would be obvious that the paddle script is what this public cell is intended for. It’s helpful for myself at least (a Padawan Grasshopper n00b). I’ll pull these training wheels off when I’m more comfortable with the construction of the syntax. Until then, overt naming is my way of learning this.

Anyway, thank you for posting.

Privacy & Terms