Kodeco Forums

Introduction to Unity Scripting

In this tutorial, learn basics of scripting in Unity by creating a classic arena shooter whereby geometric shapes try to crush you.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/980-introduction-to-unity-scripting

Hi georgi,

Thanks for the tutorial. Still going through it right now. I just wanted to bring to your attention that you missed a step in your explanations. Leading up to this point you had terrific animated gifs showing what we are supposed to do, just in case we got confused. Terrific! But as soon as you got to the actual coding you missed a step. You wrote:

“Double-click the PlayerMovement.cs script. On a Mac, this will open MonoDevelop, the IDE packaged with Unity on the Mac; on Windows, it should open Visual Studio. This tutorial assumes you’re using MonoDevelop.
Inside the class declare the following two public variables:”

You’ve used a new word: “class” without explaining what it is. (I don’t know what it is because I’m a beginner).
You’ve also used another new word after that, “declare”. I’m guessing it just means entering text, but I don’t know for sure, mostly because…
You’ve not shown us any imagery of what we’re supposed to do (like you’ve shown us up to this point).
Lastly, you’ve then used a final bit of codiing jargon (without explaining it prior) called, “public variables”. (Yup, I don’t know what this is either).

All in all, that one sentence used three new terms, without explanation, and without imagery with greater context (the screen space around it), right at a point where the “beginner” is supposed to begin…

This means that I’m now just guessing at what you’re asking me to do.

If you include an image whereby you show us the result of what you’ve done (with the context of the screen around it, not just the lines of code) this will make things a LOT clearer, and in a pivotal part of your tutorial. no less.

I hope this feedback proves helpful.

Cheers,

Mat

@georgi - an update as I’m progressing through your tutorial:

In the following bit of code you explain:
"There are couple of important things going on here:

  • FixedUpdate() is frame rate independent and should be used when working with Rigidbodies.
  • This loop checks to see if any of the input keys were pressed.
  • Here you get the direction for the pressed key, multiply it by the acceleration and the number of seconds it took to complete the last fixed frame. This produces a vector that you’ll use to move the Player object."

The highlighted words and phrases above are dropped onto the reader without follow-up context or explanation. I want to point out one in particular though, when you say, “This loop”… What loop? Where is a loop being formed? And how?

I would have liked an image with some arrows pointing out what you meant and where it is that one thing is looped to another. Still, I don’t know what this is.

Later, you will write, “In FixedUpdate(), before the closing brace of the if-statement, add the following line::
movePlayer(movement);”

I’m not sure exactly where you want this, and even though you may think what you’ve written is clear, an image showing us the final code would have been crystal clear.

I tried a few variations on putting this code where you I thought you meant for me to put it, but in all cases when I run the game I get this:

“All compiler errors have to be fixed before you can enter playmode!”

My progress through this tutorial has now come to a reluctant halt because there is no final code that I can compare what I’ve written to what I should have written, and then to repair the errors that I (quite naturally) made.

The ideas I’ll criticize here is that this tutorial assumed too much, to the point where the last assumption (which ended my progress) was that I had done everything right and never needed to see the final result of the code for me to check against.

This leaves me discouraged, and feeling as if I am stupid, whereas I would have loved to have spent the time to get this right and fix my errors, and not left feeling utterly defeated.

This is EXACTLY the type of tutorial that beginners DON’T want. Something that will confuse them and leave them feeling defeated and discouraged from trying again.
I would encourage someone, not necessarily georgi, to ammend this tutorial so that VR enthusiasts can begin their progress through Unity with ea
se.

@matbrady

Hey Mat,

I take issues like this very serious, so I’ve updated the tutorial to make it more beginner friendly.
Some terms have been clarified and I’ve added additional screenshots and graphics to make sure readers can follow along without any problems.

Terms like class, variable, public, vector etc. in regards to Unity have some additional information now, but this tutorial assumes you have some experience with C# or another programming language as this is about the specifics of scripting in Unity not about C# from scratch.

If you’re getting errors or you’re not 100% sure where to change a piece of code or a value in the editor, you can take a look at the finished project and compare it to what you have: https://koenig-media.raywenderlich.com/uploads/2016/03/BlockBusterFinal.zip

I hope you’ll give this tutorial another chance and that you’ll be able to follow along our VR tutorial, if you have any questions about either of them feel free to ask!

Cheers!

Thanks, Eric! I appreciate that. A LOT!! I’ll give it another go. :slight_smile:

Hi Eric, I’m really enjoying your style of tutorial but am having an issue with my example here. My raycast for the projectlie is tracking off in weird directions. So when I fire the projectile, it floats off in the Y axis. I’ve compared to the final and that works as intended. I’ve tried debugging the Raycast hit by following the stack trace, and in mine I’m definitely getting an on odd Direction param. Where’s the best way to upload so you can maybe help me diagnose?

Thanks in advance,
K

This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]