Last active
January 28, 2024 22:52
-
-
Save gekidoslair/2c709d829166028d41dcbbf9fb0a0a7b to your computer and use it in GitHub Desktop.
Blaze AI and Opsive UCC integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Opsive.UltimateCharacterController.Traits; | |
using UnityEngine; | |
namespace PixelWizards.GameSystem | |
{ | |
/// <summary> | |
/// Quick tutorial for anyone that's using Opsive UCC and want to integrate it with Blaze, it's super simple: | |
/// 1) setup your AI with Blaze | |
/// 2) Add a Rigidbody | |
/// 3) add (from Opsive): Attribute Manager & Health components | |
/// 4) add 'on damage' and 'on death' events to the Health components | |
/// 5) add the attached components (Damage Handler) to the AI | |
/// 6) setup the 'Take Damage' and 'On Death' events to point at the damage handler script: | |
/// </summary> | |
public class DamageHandler : MonoBehaviour | |
{ | |
private BlazeAI blaze; | |
private Health health; | |
private void Start() | |
{ | |
blaze = gameObject.GetComponent<BlazeAI>(); | |
health = gameObject.GetComponent<Health>(); | |
} | |
/// <summary> | |
/// Add this to the 'On Damage Event' on the UCC Health component | |
/// </summary> | |
public void TakeDamage(Single amount, Vector3 position, Vector3 force, GameObject thisObject) | |
{ | |
if (thisObject != null) | |
{ | |
Debug.Log("Take Damage! " + amount + " hit by " + thisObject.name); | |
// tell blaze that we were hit | |
blaze.Hit(thisObject); | |
} | |
} | |
/// <summary> | |
/// Add this to the 'On Death' on the UCC Health component | |
/// </summary> | |
public void OnDeath(Vector3 position, Vector3 force, GameObject thisObject) | |
{ | |
if (thisObject != null) | |
{ | |
Debug.Log("We died! - Killed by : " + thisObject.name); | |
// tell blaze that we died | |
blaze.Death(false, thisObject); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment