Behaviours are used to make simpler exetending npc behaviour routines. You can use them to quickly add your own NPC behaviour by overriding base class ( 'NPCBehaviour.cs' ) relevant methods.
Base class already have all combat implemented so and whats left for you is to override ‘onNonCombat()’ method to implement NPCs non comat / idle routine.
Currently, if left empty, NPC will stand in place and do nothing ( like guard behaviour ) until attacked.
If needed, attack routine can also be overriden by overriding methods ‘onCombat()’ and ‘onCombatWait()’
All virtual and abstract methods are following:
- onStart – executed on first setting behaviour
- onEnd – executed on removing the behaviour
- onNonCombat – idle state
- onReturnFromCombat – returning from combat state
- onCombatWait – in combat but waiting turn
- onCombat – in combat state
- onDeath – executed on death
- chooseAttackMethod – choosing NPC attacks
- onUpdate – update method
- onLateUpdate – late update method
- chaseCondition – additional chase condition checks if needed
- onHit – additional on hit routine if needed
- clear – clear method.
Creating New NPC Behaviour
To create new NPC behaviour, click on ‘Assets/Create/Create New Npc Behaviour’ or click on project window and summon context menu with right mouse button and choose ‘Create/Create New Npc Behaviour’.
New 'NPCBehaviour' script will be created with commented potential methods to override.
After desired behaviour is implemented, set new behaviour onto NPC, by using ‘NPCScript.setNewBehaviour (…)’ method.
As always, you can look at the examples of already implemented NPC behaviours ( NPCGuardBehaviour, NPCPatrolBehaviour, NPCFollowerBehaviour etc... )