Hello.
I am have a small problem.
I have currently switched to Unity 2018.2.1f.
In my game the player can attack using various weapons.
The way my player deals damage is by a cube that is placed infront of the player ( Damager ) with box collider set to triger.My enemy has capsule collider set to triger.
My problem is when the enemy collides with the Damager gameobject no damage gets applied.
Here is my script for the Damager gameobject.
Hrac_WEAPONMANAGER hrcWeaponManager;
public float damageToDeal;
BoxCollider damageCollider;
public Material colliderOFF;
public Material colliderON;
Material currentMaterial;
private void Start()
{
damageCollider = GetComponent<BoxCollider>();
damageCollider.enabled = false;
currentMaterial = GetComponent<Renderer>().material;
currentMaterial.color = colliderOFF.color;
}
// Update is called once per frame
void Update ()
{
if(GetComponentInParent<Hrac_WEAPONMANAGER>() != null)
{
hrcWeaponManager = GetComponentInParent<Hrac_WEAPONMANAGER>();
damageToDeal = hrcWeaponManager.damage;
}
}
public void colliderActivator()
{
StartCoroutine(colliderActive());
}
IEnumerator colliderActive()
{
damageCollider.enabled = true;
currentMaterial.color = colliderON.color;
yield return new WaitForSeconds(0.5f);
currentMaterial.color = colliderOFF.color;
damageCollider.enabled = false;
}
}
and here is the script for enemy health
public float maxHealth;
public float currentHealth;
void Start ()
{
currentHealth = maxHealth;
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "DAMAGER")
{
Hrac_DAMAGER hrcDamager = other.GetComponent<Hrac_DAMAGER>();
currentHealth = currentHealth - hrcDamager.damageToDeal;
}
}
void Update()
{
if (currentHealth <= 0f)
{
Destroy(gameObject);
}
}
}
This code is taken from my older project and everything works perfectly with no problems on older versions of Unity.
Does anybody knows what might be the problem ?