"Hitpoints remining is not being printed"

The code is not printing remaining hitpoints of the enemy even though I turned on “Send Collision Message” in collisions tab in Particle effects. Also applied Kinematic rigidbody collider along with box collider on enemy. Here is my code below, please help me understand where is the mistake in it. The game is running but it not printing anything on the console.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
 
public class EnemyDamage : MonoBehaviour
{
    
    [SerializeField] int hitPoints = 10;
    private void OnParticleCollision(GameObject other)
    {
        ProcessHits();
        if (hitPoints < 1)
        {
            KillEnemy();
        }
    }
    private void ProcessHits()
    {
        hitPoints = hitPoints - 1;
        print("Hitpoints remaining: " + hitPoints);       
    }
    private void KillEnemy()
    {
        Destroy(gameObject);
    }
 
}

Please help me with this.

Hi Akshay,

Your code looks fine to me. Is the collider a trigger collider or a normal collider?

Kinematic Rigidbodys do not collide with static or other kinematic Rigidbodys. See the table at the bottom on this page in the manual: https://docs.unity3d.com/Manual/CollidersOverview.html

This topic was automatically closed after 7 days. New replies are no longer allowed.

Privacy & Terms