I finally succeeded to write my own fall damage script based on ORK Status System, it was kinda hard for me since i'm a beginner here is the script for those who are interested and are as noob as me aha : using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ORKFramework;



public class ORKFallDamage : MonoBehaviour {

public int val;
public int health;
public float lastPosition;
public float fallDistance;
public int instantDeathVal;
public AudioClip fallSound;

public GameObject player;
private CharacterController controller;
public Combatant _combatant;
// Use this for initialization
void Start () {

controller = gameObject.GetComponent<CharacterController> ();
player = GameObject.Find("Player(Clone)");
_combatant=ComponentHelper.GetCombatant(player);
Debug.Log (_combatant.Status [1]);



}

// Update is called once per frame
void Update () {
health = _combatant.Status [1].GetValue ();

if (lastPosition > gameObject.transform.position.y) {

fallDistance +=lastPosition - gameObject.transform.position.y;

}

lastPosition = gameObject.transform.position.y;

if (fallDistance > 5 && fallDistance < 10 && controller.isGrounded) {

Debug.Log("1HP Damage");


//health = _combatant.Status [1].GetValue ();
health -=1;
_combatant.Status [1].SetValue (health, false, true, false, false, false, true);
ResetSystem ();
}
if (fallDistance < 3 && controller.isGrounded) {
Debug.Log ("No HP loss");
ResetSystem ();

}
if (fallDistance > 40 && controller.isGrounded) {
Debug.Log ("InstantDeath");
//health = _combatant.Status [1].GetValue ();
health -= instantDeathVal;
_combatant.Status [1].SetValue (health, false, true, false, false, false, true);
ResetSystem ();





}
if (fallDistance > 40 && !controller.isGrounded) {
Debug.Log ("Aaaaaaaaaah");
Fall ();
GetComponent<AudioSource>().PlayOneShot(fallSound, 0.7F);
//health = _combatant.Status [1].GetValue ();
}
}



void ResetSystem(){

fallDistance = 0f;
lastPosition = 0f;

}

IEnumerator Fall(){

GetComponent<AudioSource>().PlayOneShot(fallSound, 0.7F);
yield return new WaitForSeconds (2);
GetComponent<AudioSource>().Stop();

}




}
  • Hey thanks ! It works well ! I just have to adjust some things to integrate into my game but overall its great!
Sign In or Register to comment.