Hi, im fairly new to Unity but im trying to make a game, which as of now has 3 levels, i have a small object called “honey” that needs to be picked up by the player, when the object its picked a small explosion happens, it gives some health back to the player and it vanishes from the scene. I made a prefab of the object with the particles and audio and i used it on all levels. In Editor the explosion happens everytime the object is picked, as it should, BUT when i build the game to run on windows or WebGL, the particles stop working correctly, only working as they should in the first level, the following levels the object honey is simply picked but no explosion happens, i have been looking around and i read the solution is something to do with loading the prefab or the gameobjects feeding the prefab in a resources folder, or setting play on awake to all the particles systems, but so far i havent managed it to work, if someone could help me or just point me in the right direction. IN editor the game runs perfectly, but once i build it, it doesnt :(. the script for the honey object is this one:
"using UnityEngine;
public class PickupPicked : MonoBehaviour
{
public ParticleSystem m_ExplosionParticles;
public AudioSource m_ExplosionAudio;
public GameObject m_ExplosionPrefab;
public float honeyHealth;
GameObject player;
BeeHealth playerHealth;
private void Awake()
{
m_ExplosionParticles = Instantiate(m_ExplosionPrefab).GetComponent<ParticleSystem>();
m_ExplosionAudio = m_ExplosionParticles.GetComponent<AudioSource>();
m_ExplosionParticles.gameObject.SetActive(false);
player = GameObject.FindGameObjectWithTag ("Player");
playerHealth = player.GetComponent <BeeHealth> ();
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Player"))
{
if(playerHealth.currentHealth > 0)
{
playerHealth.currentHealth=playerHealth.currentHealth+honeyHealth;
if(playerHealth.currentHealth> playerHealth.startingHealth)
{
playerHealth.currentHealth = playerHealth.startingHealth;
}
}
m_ExplosionParticles.transform.position = transform.position;
m_ExplosionParticles.gameObject.SetActive (true);
m_ExplosionParticles.Play ();
m_ExplosionAudio.Play ();
m_ExplosionPrefab.gameObject.SetActive (false);
Destroy (m_ExplosionPrefab.gameObject);
Destroy (gameObject);
}
}
}
"