UFPS & Horse Animset Pro

I decided to share the Damage Handler that I created for myself as I’ve been using MalberS Animations asset called Horse Animset Pro (see link below) and UFPS

Link to Horse Animset Pro
Link to UFPS

Horse Damage Handler – put on the Base Horse

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
//Chris.redhawk@gmail.com - Check me out on YouTube as well youtube.com/c/RedHawkStudios
//This is using the vp_DamageHandler that comes with UFPS
//The goal is allow you to kill the horse and kill the horse while a Rider is riding.
//Currently Rows 35&36 will only damage the player on horse dieing.  Read comment on line 37 to make the player die instead
//Remove the below line if you don't want your Horse to respawn on death
[RequireComponent(typeof(vp_Respawner))]
public class vp_HorseDamageHandler : vp_DamageHandler {
	HorseController m_Controller = null;
	vp_FPPlayerEventHandler m_Player = null;
	public float riderFallDamage=0.15f;
	void Start () {
		m_Controller = (HorseController)this.GetComponent<HorseController>();
		MinDeathDelay=1.0f;//Setting this to 1 so that the Horse falls over before it dies
		MaxDeathDelay=1.0f;//Setting this to 1 so that the Horse falls over before it dies
	}
	//Horse Damaged - check health to see if dead
	public override void Damage(vp_DamageInfo damageInfo){
		base.Damage(damageInfo);
		if(CurrentHealth<=0.0f){
			DeadHorse();//Call Horse Dead Animation
		}
	}
	//Horse Died - check if player is riding or not
	public override void Die(){
		CheckMount();
	}
	//Check if Player is mounted.  If so, do stuff to player before Dieing.  If not, just Die
	public void CheckMount(){
		if(m_Controller.Mounted){//If Mounted, do stuff to the player
			m_Player=(vp_FPPlayerEventHandler)this.GetComponentInChildren<vp_FPPlayerEventHandler>();
			if(m_Player!= null){
				m_Player.SendMessage("Damage",riderFallDamage);//Damage from falling
				Dismount();
				//Other Option - comment out above two lines and uncomment below line
				//m_Player.SendMessage("Die");//Instant Kill player
			}
		}
		base.Die();
	}
	//Play Horse Death Animation
	public void DeadHorse(){
		m_Controller.anim.SetTrigger(HashIDs.deathHash);
	}
	//We have a rider, dismount before horse dies
	public void Dismount(){
		m_Player.SendMessage("DisableMounting",this.transform.position);
		m_Player.Mount.TryStop();
	}
	//Reset the Damage Handler
	protected override void Reset()
	{
		base.Reset();
	}
}
Advertisements