Hey everyone,
For some reason, my enemy ships are almost not getting hit (very rarely they do): there’s no effect, and I can’t destroy the object. But I can crash in it. Meanwhile, the sphere placeholder behaves as expected.
The issue exists for all the ships I added,
Manually adding rigidbody and simple box collider didn’t help.
The Enemy script looks same as Rick’s.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NME : MonoBehaviour
{
[SerializeField] GameObject deathVFX;
[SerializeField] GameObject hitVFX;
[SerializeField] Transform parent;
[SerializeField] int scorePerHit = 15;
[SerializeField] int hitPoints = 5;
ScoreBoard scoreBoard;
void Start()
{
scoreBoard = FindObjectOfType<ScoreBoard>();
AddRigidBody();
}
void AddRigidBody()
{
Rigidbody rb = gameObject.AddComponent<Rigidbody>();
rb.useGravity = false;
}
void OnParticleCollision(GameObject other)
{
ProcessHit();
if (hitPoints < 1)
{
KillEnemy();
}
}
void ProcessHit()
{
GameObject vfx = Instantiate(hitVFX, transform.position, Quaternion.identity);
vfx.transform.parent = parent;
hitPoints--;
scoreBoard.IncreaseScore(scorePerHit);
}
void KillEnemy()
{
GameObject vfx = Instantiate(deathVFX, transform.position, Quaternion.identity);
vfx.transform.parent = parent;
Destroy(gameObject);
}
}
Can you help me find where the issue is?