I checked and made sure the correct sounds were attached to my GameObjects, and checked Play On Awake for both of them. I instantiate the objects at the right time, and a different sound is supposed to play for each. However, they both play the same sound. What could be causing this? Thanks in advance. Here is the code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Instantiator : MonoBehaviour
{
int magnet = 2;
public GameObject HalfLit;
public GameObject Lit;
public GameObject HalfLitCopy;
public GameObject LitCopy;
public GameObject PowerBox;
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Player"))
{
magnet -= magnet;
Destroy(other.gameObject);
if (magnet != 0)
{
HalfLitCopy = Instantiate(HalfLit, PowerBox.transform.position, PowerBox.transform.rotation) as GameObject;
}
else
{
LitCopy = Instantiate(Lit, PowerBox.transform.position, PowerBox.transform.rotation) as GameObject;
}
}
}
}