At present, the only way I’m aware that a series of events can be scripted is with a deeply nested group of “if” statements. But in some instances, this can be pretty laborious and I’m wondering if there’s a better way to set this up. Take for example the following series of commands to an object:
move forward
stop when wall is reached
turn left
move forward
start timer
jump up when timer reaches 5 seconds
… and so forth
Although the actions aren’t all that complex, it still requires a fair number of “if” statements so that if I wanted a user to be able to modify step 3 on the fly to “turn right”, the code would get pretty involved.
Is there a better way to accomplish this? (I’m using Javascript).
I’ve made a pretty modular AI script. There are four base classes that extend each other and successively add more complex functionality.
After those four classes there are multiple branches that configure the AI differently and override methods to more radically change functionality.
This worked pretty well and allowed for much flexibility. All actions are split into methods and I first define a general approach but can override it in any derived class to modify it.
I also introduced some pseudo-events. Basically just methods that get called at certain points in the script and that can be overridden in derived classes to hook in other functionality.
The downside is that overriding doesn’t work in javascript and the Unity editor doesn’t like it. You’ll have to make all your properties private or protected and modify them in the script.
Adrian - Sounds like you’re already sorted out something like what I’m thinking about, although it also sounds like your implementation is more sophisticated than what I’m hoping to achieve.