Hey guys.
I have a little problem which i cant really get behind even though its probably not a hard one. I have two walls (one is a copy) and if i damage the original one, the damage gets inflicted onto the copy and then ,after it recieves enough damage, the copy gets destroyed, even though i tried to damage the original.
Heres a video of that happening: The Video
Anyway I have a “ObjectHealth” Script which is basically a very simple and normal health script with a certain life value which can get reduced and if reached zero the gameObject gets destroyed.
Heres the Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectHealth : MonoBehaviour
{
public float maxHealth = 200f;
public float currentHealth;
public GameObject deathEffectOne;
public bool isDead = false;
public GameObject objectLOL;
void Start()
{
currentHealth = maxHealth;
Debug.Log(currentHealth);
}
public void TakeDamage(float amount)
{
currentHealth = currentHealth - amount;
if (currentHealth <= 0)
{
Die();
}
}
void Die()
{
DeathEffect(deathEffectOne);
Destroy(objectLOL);
isDead = true;
}
public void DeathEffect(GameObject deathEffect)
{
Instantiate(deathEffect, transform.position, transform.rotation);
}
}
Would be nice if anyone could help