My question is how to get this working, I have this script for healing...The problem is that it increments the the health number I put in plus the entire current health number...Can any of you ladies or gentilemen help me fix this...Thx ken
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using EmeraldAI; using EmeraldAI.Example;
//Apply our needed components when attaching the script to an object [RequireComponent(typeof(BoxCollider))] [RequireComponent(typeof(Rigidbody))] public class Heal : MonoBehaviour { public enum TargetType { Player = 0, AI = 1, NonAITarget = 2 }; public TargetType TargetTypeRef = TargetType.Player; public enum InteractionTypeEnum { Healing = 0, Damage = 1 }; public InteractionTypeEnum InteractionType = InteractionTypeEnum.Healing; public int DamageAmount = 5; public int HealingAmount = 1; bool AIPresent = false; EmeraldAISystem EmeraldAISystem; EmeraldAIPlayerHealth PlayerHealthSystem; Coroutine HealCoroutine;
//Set our components to the right setting on Start
void Start()
{
GetComponent<BoxCollider>().isTrigger = true;
GetComponent<Rigidbody>().isKinematic = true;
}
void OnTriggerEnter(Collider C)
{
//Check to see if our Emerald AI component is on the collision object.
if (C.gameObject.GetComponent<EmeraldAIPlayerHealth>() != null)
{
//Get a reference to the collision object's Emerald AI system and store it.
PlayerHealthSystem = C.gameObject.GetComponent<EmeraldAIPlayerHealth>();
if (InteractionType == InteractionTypeEnum.Damage)
{
//Damage our collision object's Emerald AI system. In this eaxample, the player is doing damage.
int TargetTypeCobverter = (int)TargetTypeRef;
EmeraldAISystem.Damage(DamageAmount, (EmeraldAISystem.TargetType)TargetTypeCobverter);
}
else if (InteractionType == InteractionTypeEnum.Healing && !AIPresent)
{
//Start our healing coroutine
//AIPresent = true;
PlayerHealthSystem.CurrentHealth += HealingAmount;
}
}
}
//Cancel collision
void OnTriggerExit(Collider C)
{
AIPresent = false;
EmeraldAISystem = null;
}
}
Answer by Wilomomo · Dec 12, 2019 at 03:36 PM
You have to clamp your health point =)
Modify at line 26
PlayerHealthSystem.CurrentHealth += HealingAmount;
PlayerHealthSystem.CurrentHealth = Mathf.Clamp(PlayerHealthSystem.CurrentHealth, 0, MaxHealthPoint);
Your answer
Follow this Question
Related Questions
I am having problem with my game mode. 0 Answers
Unity Web Player not installing 6 Answers
How can i turn around my ai when player is behinde him ?, 0 Answers
3D Rope swing on one axis no matter what 1 Answer
My Player is floating in air 0 Answers