PLEASE HELP ME!!! I am making a 2D game in which the player shoots a bullet at an airplane and when the bullet comes into contact with the airplane, the score increments. The airplane and bullet are both Quads, but they have Box Collider 2Ds instead of Mesh Colliders. One problem I have been struggling on for the last 1 to 3 HOURS is that even though I have declared the Particle System as a public variable, and I have assigned an explosion Particle System to it, when the game is being played and the bullet collides with the airplane, the score increments as I programmed it to, but the particle system doesn’t play and throws up an error: UnassignedReferenceException: The variable destroyParticleSystem of BulletMovement has not been assigned.
even though I assigned the particle system to it! This happened to me twice, the time of this writing being the second time. The first time I thought it was some sort of bug in Unity and deleted the prefab and the script and wrote it again. Yet it still doesn’t work.
This is the Bullet’s code:
public class BulletMovement : MonoBehaviour
{
[SerializeField] private float speed = 15f;
public static float score;
public ParticleSystem destroyParticleSystem;
void Start()
{
Invoke("DestroyThis", 2f);
}
void FixedUpdate()
{
transform.position += new Vector3(0, speed * Time.fixedDeltaTime, 0);
}
void DestroyThis()
{
Destroy(gameObject);
}
void OnTriggerEnter2D(Collider2D collinfo)
{
if (collinfo.gameObject.tag == "Airplane")
{
score += 1;
Debug.Log("Hit airplane");
destroyParticleSystem.Play();
}
}
}
I would really grateful if anyone can give me an answer to this problem.