Hi,
I’m playing around with the Roll a Ball Tutorial and have started adding my own things to it.
I have a Main Menu with an audio listener attached to the camera. From this screen I can access “Test Level”.
Test Level contains a Ball(Tag = untagged), a Pickup(Tag = Pickup10) and a PickupTrigger(Tag = PickupTrigger) surrounding the Pickup. The aim being that when the ball rolls into the cube:
A particle effect appears
A sound effect plays
the cube and trigger disappear 1/2 a second later.
(the 1/2 second is to allow the effect to play)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PickupEffect : MonoBehaviour {
public ParticleSystem effect;
public GameObject trigger;
public AudioSource pickupSound;
void OnTriggerEnter (Collider other)
{
if (GetComponent<Collider> ().gameObject.CompareTag("PickupTrigger"))
{
effect.Play();
pickupSound.Play();
StartCoroutine(StopTrigger());
}
}
IEnumerator StopTrigger()
{
yield return new WaitForSeconds(0.5f);
trigger.SetActive(false);
}
}
The correct Particle System is placed into “effect”
The trigger is placed into “trigger”
the sound effect is placed into “AudioSource”
The ball rolls into the pickup trigger, the particle effect plays and the pickup disappears. However, no sound plays.
I have a similar scene setup with what seems to be the same code and that works fine, but if I import the code into this project and set it up the same, no sound plays.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Trigger : MonoBehaviour {
public ParticleSystem effect;
public GameObject trigger;
public AudioSource pickupSound;
void OnTriggerEnter(Collider other)
{
if (GetComponent<Collider>().gameObject.CompareTag("PickupTrigger"))
{
effect.Play();
pickupSound.Play();
StartCoroutine(StopTrigger());
}
}
IEnumerator StopTrigger()
{
yield return new WaitForSeconds(0.5f);
trigger.SetActive(false);
}
}
I’m at a loss as to what is going wrong, can someone help please?