pyunity.script module

Module to manage loading scripts from files.

class pyunity.script.Behaviour[source]

Bases: pyunity.core.Component

Base class for behaviours that can be scripted.

gameObject

GameObject that the component belongs to.

Type:GameObject
transform

Transform that the component belongs to.

Type:Transform
AddComponent(component)

Calls AddComponent on the component’s GameObject.

Parameters:component (Component) – Component to add. Must inherit from Component
GetComponent(component)

Calls GetComponent on the component’s GameObject.

Parameters:componentClass (Component) – Component to get. Must inherit from Component
Start()[source]

Called every time a scene is loaded up.

Update(dt)[source]

Called every frame.

Parameters:dt (float) – Time since last frame, sent by the scene that the Behaviour is in.
pyunity.script.CheckScript(text)[source]

Check if text is a valid script for PyUnity.

Parameters:text (list) – List of lines
Returns:If script is valid or not.
Return type:bool

Notes

This function checks each line to see if it matches at least one of these criteria:

  1. The line is an import statement
  2. The line is just whitespace or blank
  3. The line is just a comment preceded by whitespace or nothing
  4. The line is a class definition
  5. The line has an indentation at the beginning

These checks are essential to ensure no malicious code is run to break the PyUnity engine.

pyunity.script.LoadScripts(path)[source]

Loads all scripts found in path.

Parameters:path (Pathlike) – A path to a folder containing all the scripts
Returns:A module that contains all the imported scripts
Return type:ModuleType

Notes

This function will add a module to sys.modules that is called PyUnityScripts, and can be imported like any other module. The module will also have a variable called __pyunity__ which shows that it is from PyUnity and not a real module. If an existing module named PyUnityScripts is present and does not have the __pyunity__ variable set, then a warning will be issued and it will be replaced.