hi, i wanted help with damage, so i just made a simple script, it's just an image which damages the player when collides with the player, but for some reason the player takes damage of 2 hp instead of 1, and i can't figure out why that happens and how to fix it
.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DamageOnCollision : MonoBehaviour
{
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
collision.gameObject.GetComponent().TakeDamage(1);
}
}}
↧