C# for applications vs C# for Unity help
I have been wondering this for quite awhile. I am a new programmer so I will try to explain this to the best of my knowledge.
In Unity, your script might include something like this: transform.position = Vector3.Lerp(transform.position, targPos, Time.deltaTime * speed);
This of course is written in the language C#. But if you are writing in C# not using Unity, you don't have access to things like transform.position or Time.deltaTime, they would only work in Unity.
If this is the case, how would one be fluent in the languge C#? How would professional programmer, be a professional? Would they have to memorize a bunch of functions and things like Vector3 just to make a game? How would they implement a feature if it was their first time, and they were "fluent" in C#?
Answer by Zee-Play · Feb 22, 2017 at 03:43 AM
I can tell you how I learned to use Unity. I'm pretty much a hobby coder, 99% self taught. Had absolutely no idea how to write C# language when I picked up unity, only a few memories from basic coding back in highschool 8 years ago.
I started out by looking at examples, trying out simple stuff, and searching unity answers and the unity manual every time I hit a rock in the road.
Didn't force my self to learn the unity library here https://docs.unity3d.com/Manual/index.html All of those scripts get stuck in your head the more you use them, after a while not having to check the manual for syntax.
Went from the simplest of stuff, like moving a sphere left right, to more advanced stuff.
Answer by dpoly · Feb 22, 2017 at 04:22 AM
You learn C# by writing C# to solve programming problems. It's easier to start outside Unity, using plain Visual Studio Express. Lots of tutorials, I can't recommend one, but do 10 or 20 or more. Then on to Project Euler. Avoid UI or database, that's not what you need for games.
The coding needs to be simple and natural so you can concentrate on the actual hard parts of your game.
Answer by UnityCoach · Feb 22, 2017 at 07:01 PM
Just like with foreign languages, the language is one thing, the subject another. You can be fluent in a language and yet miss the vocabulary to talk about a given topic.
In regards to C# in Unity VS C# for apps, the main difference between apps and video games, is that an app can have the user wait (you know, the spinning wheel thing), while a game should never go below a target frame rate, usually 60. In Unity, like in most game engines, there's a main loop, that'll update the game world and refresh the screen. This is the message that every component receive when the implement an Update () method. When things take longer than a frame to do (ie: things like downloading extra content or loading a level), we use coroutines to split a process across several frames.
Now, with Unity like with any other API based environment, you never know every thing about it. You rely on the documentation. At the beginning of a script, there are some "using". They explicitly tell the compiler which assembly the class you declare will rely on. Like using UnityEngine for everything Unity, and using UnityEditor for everything Unity Editor related. You can add more, like using UnityEngine.UI to implement some UI stuff, or using System.Collections.Generic to use generic list and dictionaries, or other System assemblies.
I personally learnt using Unity documentation along with C# Programming Guide from MSDN, and with a great mentor too, who taught me a great deal on object oriented programming. Though, there are also design patterns that apply to apps more than games, and somehow go against the component approach suggested (and only suggested) by Unity. What you may find a little difficult to grasp, is that some words are keywords, like public, private, static, protected, sealed, abstract, interface, etc, while some others are just ideas, like generic, singleton, instance, factory, model-view-controller, etc.
So, what's important as you progress is to fully understand what's behind the syntax, like :
transform.position = Vector3.Lerp(transform.position, targPos, Time.deltaTime * speed);
transform is a shorthand to access the Transform component on the same GameObject. .position is the world position property of the transform component, it's of type Vector3 Vector3 is a variable type, it belongs to UnityEngine types can implement methods Vector3 offers a Lerp (Linear Interpolation) method that takes 3 arguments ; from, to and interpolation level, here it's given the position of the object, another position, and an interpolation state that uses Time.deltaTime multiplied by a speed value Time is a class of UnityEngine that tells everything about time in the game and .deltaTime is how much time has elapsed since last Update. Although this is pretty popular technique, it's not the way Lerp is meant to be used, as with this implementation, the object will almost never reach the target, it's like dividing any number by 2, no matter how many times you divide, there's always something left. But that's another story :)
Check out my youtube channel for some free videos, and if you're interested, here's a complete training course I put together on programming with Unity.
Your answer
Follow this Question
Related Questions
IAP function not calling 0 Answers
In Game Programming Language 1 Answer
How to make a surface glow when its hit by a laser. 0 Answers