NetPrints Unity Tutorial
Description
This is an example of how to use NetPrints inside Unity3D for visual programming. It replicates part of the roll-a-ball tutorial where we make a ball roll with user input. For further information on how the example works please visit the link. The completed project is contained in this repository.
Steps
- Create a new project within your unity project. Create a plane for the floor and a sphere. Add a
Rigidbody
to the sphere. The exact path does not matter. Unity will automatically find the generated scripts.
- Click assemblies in the main menu. Remove all existing items and add Unity’s .NET libraries (
mscorlib.dll
,System.dll
,System.Core.dll
) which can be found in<UnityDirectory>/Editor/Data/Mono/lib/mono/unity/
as well asUnityEngine.dll
inF:/Unity/Editor/Data/Managed
.
- Unity can use either our generated .NET binary or C# source code. The source code has the advantage that we can debug our generated code. Furthermore there are some bugs in Unity with generated .NET binaries and MonoBehaviour inheritance. Set the output mode to
SourceCode
which will output only the source code. Then pressNew Class
which will add a new empty class to our project. You can open it by clicking on it. In the class settings it is possible to change the class name, its namespace and some other interesting properties. Set the base class toUnityEngine.MonoBehaviour
.
- Add the
Update()
andStart()
methods. Also create therb
(typeUnityEngine.Rigidbody
) andspeed
(typeSystem.Single
, which is the same asfloat
). Mark thespeed
attribute as public by clicking on it and checking thePublic
checkbox on the right side of the editor.
- Implement the
Start()
method.
- Implement the
FixedUpdate()
method.
- Press compile. This will generate a source code file with the name
<Namespace.Class>.cs
. Since Unity only recognizes classes with the same name as its filename, the generated file will need to have the namespace part removed. The script can now be dragged onto our sphere like any other C# script. The sphere should now move when we press WASD.
Written on March 16, 2019