
#Adventure creator unity ai actions code
Inside this function, write the following code to expose the two variables in the editor: objectToAffect = (GameObject) EditorGUILayout.ObjectField ("GameObject to affect:", objectToAffect, typeof (GameObject), true) The Action's GUI is written in the ShowGUI function. NOTE: These variables must be public so that they can be serialized (saved) properly by Unity. Declare the following two public variables: // Declare variables here We want this Action's GUI to have two fields: which GameObject to affect, and whether to turn the gravity on or off. Save the script, and let Unity import it. Do this by replacing the instance of ActionTemplate with ActionGravity on line 22. To remove the Console error, we just have to rename the class name and constructor. But first, move the new script file to a new folder, where all your custom Actions are to be stored. The Console window will display an error, but this will disappear once we edit the script. Within your asset folder, look for the script ActionTemplate.cs, found in AdventureCreator / Scripts / ActionList.ĭuplicate the file, and rename the copy ActionGravity. Rather than writing a new script from scratch, we can use the included template file as a basis. Note that this tutorial is not a guide to scripting: just one on writing custom code that can be used by Adventure Creator.Įach Action is contained within it's own script file. In this tutorial, we'll write an Action that can enable or disable gravity to any GameObject's Rigidbody component.

While Adventure Creator includes more than 50 "official" Actions, it's possible to extend the toolkit further by writing custom Actions, which are useful when we need to perform tasks outside the scope of a traditional adventure. An Action is designed to perform a specific task, and Actions chained together in an ActionList can form Cutscenes, Interactions, and any logic sequence in a game.

Actions are at the core of Adventure Creator.
