I would appreciate if anybody could help with this simple problem. I’m learning Unity script following a book and although I copy the script exactly as it appears on the book the Unity editor says there are compile errors and the script cannot run. I’m wondering if that is because Unity uses visual studio instead of Monodevelop that is used in the book.
Here is a screen shot of the script.
You should really learn C# by itself first before trying to use it in unity. There are lots of online resources like Codeacademy and other tutorials you can use to learn C#.
The error is that he’s trying to write an integer number into a Debug.Log function which expects a string.
Correct way to output your result would be,
int myResult = 11 + myNumber;
Debug.Log(myResult.ToString());
Or, shorter but less readable way,
Debug.Log((11 + myNumber).ToString());
@games28 , Here’s a tutorial series from which I started:
I would also recommend trying to learn a bit of XNA / MonoGame coding and get a solid grip on a few concepts there. Then try Unity scripting.
While I’m all for “learning by doing”, scripting logic within a game engine does require having a few basics down first.
EDIT == Oh and, also, when you say “but it just throws an error”, you are REALLY going about problem solving the wrong way around. Error messages are your best friend to figuring out what’s wrong, and most commonly they tell you how to fix it! Read the error messages!
Thanks all of your for your help. You are right that I should learn C# first before going to Unity. But I didn’t know that there are free online courses out there for C#.
There are free online courses for everything in between making a lifesize Batmobile in origami, to 10-meter arc solid state Tesla coils.
You can be sure there are a few good programming resources out there
My advice, for basic programming tutorials, stay away from youtube. Congratz to exceptions, but people generally are very bad at objectively explaining logical contents. Instead of “this is how it is”, it turns into “this is how I see it”, which usually devolves down into “just write this, doesn’t matter what it means, it has to be there”.
Youtube tutorials generally get OK at solving a particular problem or something of a “narrow field” though.