Hello everyone!
I’m making my character decrease Hp on a certain collision that is tagged as Harmful.
But I’m having trouble decreasing the Hp with specific amount.
See I’m like trying to make my character decrease a certain amount of hp given from the Damage of the collided object.
So I made 2 separate scripts one that has all of my characters functions and Hp and what not and one that has a script named Damage.
If my Character collides with the Object my Character minuses Hp from the given damage from the script. Such as 25 points, 200 points and so on.
I tried doing this with my script but for some reason my DamagePoints Var is Highlighted as red.
void OnTriggerStay2D (Collider2D coll) {
if (coll.gameObject.tag == "Harmful") {
coll.gameObject = coll.GetComponents(typeof(Damage).DamagePoints - HP);
}
}
Here’s my Damage Script. Although it’s pretty simple.
Inside my public float DamagePoints I have it set as 25.
using UnityEngine;
using System.Collections;
public class Damage : MonoBehaviour {
public float DamagePoints;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}