NetPrints Unity tutorial

16 March 2019 · from the archive

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.

  1. Create a new project within your Unity project. Create a plane for the floor and a sphere, and add a Rigidbody to the sphere. The exact path does not matter: Unity finds the generated scripts automatically.
  2. 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 as UnityEngine.dll in <UnityDirectory>/Editor/Data/Managed.
  3. 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 MonoBehaviour inheritance, so set the output mode to SourceCode. 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 to UnityEngine.MonoBehaviour.
  4. Add the Update() and Start() methods, and the attributes rb (type UnityEngine.Rigidbody) and speed (type System.Single, the same as float). Mark speed as public by clicking on it and checking Public on the right side of the editor.
  5. Implement the Start() method.
  6. Implement the FixedUpdate() method.
  7. 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.