Running simple Python scripts inside Unity
Unity Python is a package that allows Python code to be executed as part of a Unity project. In this recipe, we’ll install the package, test the Python Script Editor window with a traditional Hello World
Python print
statement, and create C# scripts to run Python based on the examples provided by Unity at https://docs.unity3d.com/Packages/com.unity.scripting.python@4.0/manual/inProcessAPI.html.
How to do it...
To run simple Python scripts inside Unity, follow these steps:
- Create a new 2D project.
- Open the Package Manager by navigating to Window | Package Manager.
- Set the list of packages to those in the Unity Registry and search for Python Scripting. Then, click Install.
Figure 19.24: Adding the Python Scripting package to a project
- Open the Python Script Editor panel by going to Window | General | Python Script Editor.
- Enter
print ('Hello World from Python')
in...