Attackers dont take damage

atackers dont take damage, i do how Rick do and they dont take damage

Hi,

Are there any error messages in your Console? Please share more information on what you did and have in your project.

The code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Projectile : MonoBehaviour
{

    public float speed;
    public float damage;


    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector2.right * speed * Time.deltaTime);            
    
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        var healt = collision.GetComponent<Health>();
        healt.DealDamage(damage);
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Health : MonoBehaviour
{

    public float health = 100f;


    public void DealDamage(float damage)
    {
        health -= damage;
        if(health < 0)
        {
            Destroy(gameObject);
        }

    }

}

here is lizard prefab


and here is projectile prefab

Add a Rigidbody2D to the Zucchini and set the gravity to 0.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.