I made a game but some of the scripts don’t work when i build it but there are no error. One of the scripts that don’t work are the Enemy script. The enemies won’t split into two more enemies can anyone tell me why here’s the script
using UnityEngine;
public class Enemy : MonoBehaviour
{
// public
public CameraShake camShake;
public GameObject smallSplitter;
public ParticleSystem ps;
public float duration;
// private
GameObject player;
SoundManager sm;
// void
void Start()
{
player = GameObject.FindGameObjectWithTag("Player");
camShake = Camera.main.GetComponent<CameraShake>();
sm = GameObject.FindGameObjectWithTag("SM").GetComponent<SoundManager>();
}
void OnCollisionEnter2D(Collision2D other)
{
if (other.collider.tag == "Player")
{
// death
Destroy(this.gameObject);
sm.DeathS();
// boost up
player.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);
// split
Instantiate(smallSplitter, transform.position + transform.forward * 2, transform.rotation);
Instantiate(smallSplitter, transform.position + transform.right * 2, transform.rotation);
// Score
Score.playerScore += 15;
//shake
camShake.Shake(duration);
// particles
Instantiate(ps, transform.position, Quaternion.identity);
// health
player.GetComponent<PlayerHealth>().numOfHearts += 1;
}
}
}