Skip to content

Instantly share code, notes, and snippets.

@fivemoreminix
Created August 5, 2018 17:37
Show Gist options
  • Save fivemoreminix/dce3f83c402251f2f48583c2a1be18da to your computer and use it in GitHub Desktop.
Save fivemoreminix/dce3f83c402251f2f48583c2a1be18da to your computer and use it in GitHub Desktop.
I talk about C++ or C# for Unity to someone who doesn't know what C# is.
RifToday at 12:21 PM
Hi, about that message I sent yesterday in the coding server, I know basics and some functions in c++, but I don't know how to use it on Unity and which functions are more useful, currently I wanted to learn how to structure an RPG and some tips on how to make a bullet hell work.
aeslToday at 12:24 PM
Okay, well I can give you a quit direction to follow. You will probably have trouble using C++ as your language in unity since it may not have bindings (look up "Unity C++ bindings"), so C# may be a good option instead. In order to even get your C++ code to be executed by your C# code (you have to probably call your C++ from a tiny C# script), your C++ must be compiled to a dynamic library most likely (a .dll file on windows) or possibly, if you're lucky, a static library (or .lib on windows)
That's the quick guide on how to do that
but I've never used C++ with Unity before, I know for a fact that it is possible. just either it will be tricky or easy
RifToday at 12:25 PM
What are the differences between c++ and c# ?
aeslToday at 12:28 PM
C++ is a compiled (to binary) general programming language designed for making cross platform applications that run at a high performance. C++ is challenging on high level things (like games), so C# is a programming language made to fix that cause. It also runs at a relatively good performance, and can be used to make applications and games. It can be compiled to C++, which is in turn compiled to binary, or the C# can be compiled to bytecode which is a binary that any computer can read and not just one CPU.
For example
Unity is written in C++, and the entire engine is written in C++, but the games are programmed in C# and then compiled to C++ automatically (using IL2CPP)(edited)
RifToday at 12:29 PM
Ok, that explanation helped a lot already, is programming in C# much different than programming in c++?
aeslToday at 12:30 PM
you should consider trying to learn or use C# as it is a very commonly used language and it is made to resemble C++
not that different
for example
```cs
using System;
double add(double x, double y) {
return x + y;
}
void main() {
Console.WriteLn(add(3, 2));
}
```
c# ^
```cpp
#include <iostream>
double add(double x, double y) {
return x + y;
}
void main() {
std::cout << add(2, 3) << std::endl;
}
```
c++ ^
essentially the syntax is the same but the standard library is very different
RifToday at 12:34 PM
I see, that cleared lots of stuff already, I'll search for a tutorial to learn the libray differences, thanks a lot for your time.
If needed, can I ask you other questions in the future?
aeslToday at 12:34 PM
yeah sure no problem
and I'm glad I could help
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment