In the AI Tree you can easily create your own task by using scripting API. In this page we will show how you can do it.
In this context, we believe that you have already read the previous pages of User Scripting section.
In the previous section, we created a task for the platform moving. Let's create unique key for defining point A, B and speed.
Create new script and call it PlatformKey, after creation open it script in you scripts editor tool.
Create -> MonoBehaviour Script
Default Unity MonoBehaviour script template.
usingUnityEngine;publicclassPlatformKey:MonoBehaviour{ // Start is called once before the first execution of Update // after the MonoBehaviour is createdvoidStart() { } // Update is called once per framevoidUpdate() { }}
First of all we need to decide what we will define as key. Let's create new struct PlatformData. Don't forget to add [Serializable] attribute for custom types.
usingUnityEngine;usingSystem;[Serializable]publicstructPlatformData{publicVector3 pointA;publicVector3 pointB;publicfloat speed;}publicclassPlatformKey:MonoBehaviour{ // Start is called once before the first execution of Update // after the MonoBehaviour is createdvoidStart() { } // Update is called once per framevoidUpdate() { }}
Now we are ready to define our PlatformData key. We need to change the PlatformKey class.
Remove all methods.
Change MonoBehaviour parent class to Key<PlatformData>