Hello,I am currently working on the melee part and I need some help.My game is a mobile game and every tutorial i find is for PC.I want to make the Main Character to take damage if he collides with an enemy.Also the Main Character could attack the enemy if he is close by. I am new to Unity programming and I will be very thankful if ill get even only a hint.Thanks!
P.s. I got the script ideas from Brackeys.
MainCharacter’s Damage Script
public Transform attackPoint;
public float attackRange = 0.5f;
public LayerMask enemyLayers;
public void Attack()
{
Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers);
foreach(Collider2D enemy in hitEnemies)
{
Debug.Log("We hit" + enemy.name);
}
}
// Update is called once per frame
void Update()
{
}
void OnDrawGizmosSelected()
{
if(attackPoint == null)
Gizmos.DrawWireSphere(attackPoint.position, attackRange);
}
Health Bar script
public Slider slider;
public void SetMaxHealth(int health)
{
slider.maxValue = health;
slider.value = health;
}
public void SetHealth(int health)
{
slider.value = health;
}