Taking Damage / Healing
JU Health Component
It is important that your character has a health bar and receives damage, for this you can add the JU Health script to your character

Taking Damage
Damage Trigger
The Damage Trigger is a simple script to give damage to a character, you need to use it together with a collider with the parameter "Is Trigger" turned on, you can adjust the damage and choose the tag of which character you want to take damage.
if you leave "Character Tag" empty, the Damage Trigger will damage any character that has JU Health.

JU Damager
The JU Damager is a more complex option for dealing damage to a character, you can use it as a trigger, normal collider with a rigidbody, or as a raycast.
It supports Particles and Audio effect, it is the same component used in Malee weapons and HitBoxes

Damage by code
To deal damage to a character that has a JU Character is very simple, just call the JUHealth.DoDamage(5);
method.
See the example below:
using UnityEngine;
// >> must use JUTPS lib to acess JUHealth component <<
using JUTPS;
public class DamageOnTriggerEnter : MonoBehaviour
{
[SerializeField] private float Damage = 5;
private void OnTriggerEnter(Collider other)
{
//Get JU Health component
if (other.TryGetComponent(out JUHealth health))
{
//Damage Character
health.DoDamage(Damage);
}
}
}
This script is designed to be attached to a GameObject in Unity with a collider wich the parameter "Is Trigger" turned on. When another GameObject enters in trigger, it tries to find a JUHealth component on that GameObject and applies damage to it using the value stored in the Damage
field.
How to heal a character
Healing a character is as easy as taking damage.
Health Power Up
A Health Power Up Prefab is already included by default that adds some health points to the player:
How to heal by code
To heal a character just add Health Points(HP) to the Health variable, for example:
JUHealth
.Health += 10;
<- That line of code will add 10 health points when called
See this example below
using UnityEngine;
// >> must use JUTPS lib to acess JUHealth component <<
using JUTPS;
public class Regenerate : MonoBehaviour
{
[SerializeField] private JUHealth CharacterHealth;
[SerializeField] private float HealthPointsToAdd = 2;
// Update is called once per frame
void Update()
{
// > Prevents it from continuing to add health points infinitely
if(CharacterHealth.Health == CharacterHealth.MaxHealth) return;
// > Regenerates health points per second (HealthPointsToAdd)
CharacterHealth.Health += HealthPointsToAdd * Time.deltaTime;
}
}
The script above is a simple health regeneration system, it will add HP over time.
Last updated