EDIT: If there was a competition for the stupider person in the world I would have won the first place. The script was returning if the object tag was “Weapon” which shouldn’t. Fixed
I have a script that gives damage to an enemy, the problem is that’s not working anymore.
The script is attached to the player’s weapons, left and right. These weapons can disable/enable themselves based on the enemy position. All my players are prefabs so I can spawn them in the world. Now the problem is that the script doesn’t work even if I try to print something in the console using the update function.
Here is my code:
using UnityEngine;
using Random = UnityEngine.Random;
public class PlayerDamageController : MonoBehaviour
{
public float maxDamage;
public float minDamage;
public float maxExtraDamage;
public float minExtraDamage;
private void Update()
{
Debug.Log("Test");
}
private void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log(this.gameObject.tag);
if (this.gameObject.CompareTag("Weapon")) return;
GameObject other = collision.gameObject;
if (other.CompareTag("Bone") || other.CompareTag("EnemyTarget"))
{
float damage = Random.Range(minDamage, maxDamage);
if (other.name == "Head")
{
damage += Random.Range(minExtraDamage, maxExtraDamage);
}
if (!other.CompareTag("Weapon"))
{
EnemyHealthBar.Instance.DecreaseHealth(damage);
}
}
}
}