Hello i want to sub some HP to my character when he receives fall damages from a third party script but i can't find a way to bind my hp to the health variable of the script here is the example :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ORKFramework;
using ORKFramework.Behaviours;


public class ORKFallDamage : MonoBehaviour {

public int health;
public float lastPosition;
public float fallDistance;

public GameObject player;
private CharacterController controller;

// Use this for initialization
void Start () {

controller = gameObject.GetComponent ();
player = GameObject.Find("Player(Clone)");
Combatant combatant=ComponentHelper.GetCombatant(player);
Debug.Log (combatant.Status [1]);
health =combatant.Status[1];

}

// Update is called once per frame
void Update () {

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

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

}

lastPosition = gameObject.transform.position.y;
if (fallDistance >= 5f && controller.isGrounded) {


}
}
}

PS : my script isn't finished i can end it myself but i can't find a way to get this status value :D
  • Well, combatant.Status[i] isn't an int, it's a class handling that status value, with functions to get or change the value of the stat.

    E.g.: if you want to get the current value of the stat:
    health = combatant.Status[1].GetValue();
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Thank you, i just found it from my side lol but for example when i say : health -=1 it doesn't change the status value sorry i don't really understand, to make it faster how could i just sub 1 hp when my player takes fall damage i'm stuck : my fall damage script : 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 && controller.isGrounded) {

    Debug.Log("On se prend un poitn de degat");
    //health = _combatant.Status [1].GetValue ();
    health -= 1;
    ResetSystem ();
    }
    if (fallDistance < 3 && controller.isGrounded) {
    Debug.Log ("Chute non létale");
    ResetSystem ();

    }
    if (fallDistance > 15 && controller.isGrounded) {
    Debug.Log ("On est sensé mourrir");
    //health = _combatant.Status [1].GetValue ();
    health -= instantDeathVal;
    ResetSystem ();
  • Status.GetValue() returns an int type -- which is a value type and not a reference type.

    So the variable health contains the value type retrieved by Status.GetValue().

    To change its value via script, you need to use Status.SerValue(newValue).
Sign In or Register to comment.