using UnityEngine;
using System.Collections;
using ORKFramework;
using ORKFramework.Behaviours;
public class FallDamage : MonoBehaviour
{
//public Transform healthbar;
public float startYPos;
public float endYPos;
public float playerHealth;
public float currentHealth;
public float fallDamage;
public float damageThreshold = 10;
public bool damageMe = false;
public bool firstCall = true;
// Update is called once per frame
void Update ()
{
if (!GameObject.FindObjectOfType<CharacterController>().isGrounded)
{
if (gameObject.transform.position.y > startYPos)
{
firstCall = true;
}
if (firstCall)
{
startYPos = gameObject.transform.position.y;
firstCall = false;
damageMe = true;
}
}
if (GameObject.FindObjectOfType<CharacterController>().isGrounded)
{
endYPos = gameObject.transform.position.y;
if (startYPos - endYPos > damageThreshold)
{
if (damageMe)
{
Combatant combatant = ComponentHelper.GetCombatant(gameObject);
currentHealth = combatant.Status [1].GetValue ();
fallDamage = (startYPos - endYPos - damageThreshold);
playerHealth = (currentHealth - fallDamage);
//healthbar.GetComponent<HealthBar>().Damage(startYPos - endYPos - damageThreshold);
damageMe = false;
firstCall = true;
}
}
}
}
}
It looks like you're new here. If you want to get involved, click one of these buttons!
using UnityEngine;
using System.Collections;
using ORKFramework;
using ORKFramework.Behaviours;
public class FallDamage : MonoBehaviour
{
//public Transform healthbar;
public float startYPos;
public float endYPos;
public float playerHealth;
public float currentHealth;
public float fallDamage;
public float damageThreshold = 10;
public bool damageMe = false;
public bool firstCall = true;
// in-game
private Combatant combatant;
void Start()
{
this.combatant = ComponentHelper.GetCombatant(gameObject);
if(this.combatant == null)
{
GameObject.Destroy(this);
}
}
// Update is called once per frame
void Update()
{
if(!GameObject.FindObjectOfType<CharacterController>().isGrounded)
{
if(gameObject.transform.position.y > startYPos)
{
firstCall = true;
}
if(firstCall)
{
startYPos = gameObject.transform.position.y;
firstCall = false;
damageMe = true;
}
}
if(GameObject.FindObjectOfType<CharacterController>().isGrounded)
{
endYPos = gameObject.transform.position.y;
if(startYPos - endYPos > damageThreshold)
{
if(damageMe)
{
fallDamage = (startYPos - endYPos - damageThreshold);
this.combatant.Status[1].AddValue((int)-fallDamage, false, true, false, true, true, true);
damageMe = false;
firstCall = true;
}
}
}
}
}
It's pretty simple - get the combatant in a Start function (no need to do this every frame) and use the AddValue function of the status value to subtract the fall damage. I've set it up so that it ignores potential barriers :)
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!