NetPrints Unity tutorial
This example shows how to use NetPrints inside Unity3D for visual programming. It replicates part of Unity’s roll-a-ball tutorial, where a ball rolls with user input. The completed project is in this repository.
- Create a new project within your Unity project. Create a plane for the floor and a sphere, and add a
Rigidbodyto the sphere. The exact path does not matter: Unity finds the generated scripts automatically.
- Click Assemblies in the main menu. Remove all existing items and add Unity’s .NET libraries (
mscorlib.dll,System.dll,System.Core.dll), found in<UnityDirectory>/Editor/Data/Mono/lib/mono/unity/, as well asUnityEngine.dllin<UnityDirectory>/Editor/Data/Managed.
- Unity can use either the generated .NET binary or C# source code. Source code can be debugged, and Unity has some bugs with generated .NET binaries and
MonoBehaviourinheritance, so set the output mode toSourceCode. Then press New Class to add an empty class to the project, and open it by clicking on it. In the class settings, set the base class toUnityEngine.MonoBehaviour.
- Add the
Update()andStart()methods, and the attributesrb(typeUnityEngine.Rigidbody) andspeed(typeSystem.Single, the same asfloat). Markspeedas public by clicking on it and checking Public on the right side of the editor.
- Implement the
Start()method.
- Implement the
FixedUpdate()method.
- Press Compile. This generates a source file named
<Namespace.Class>.cs. Unity only recognizes classes whose name matches the file name, so remove the namespace part from the file name. The script can now be dragged onto the sphere like any other C# script, and the sphere moves when you press WASD.