- Home /
Question by
XGamerMarc0 · Nov 18, 2016 at 01:43 AM ·
sounds
I am Trying to make the AudioSource to play when "pickup" is trigger but won't work
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag ("PickUp"))
{
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
if (Pickup)
{
GetComponent<AudioSource>().clip = PickUpUFO;
GetComponent<AudioSource>().Play ();
}
}
void SetCountText()
{
countText.text = "Count: " + count.ToString ();
if (count >= 12)
{
winText.text = "You Win!";
}
}
}
Comment
What is this second if statement for?
if (Pickup)
{
GetComponent<AudioSource>().clip = PickUpUFO;
GetComponent<AudioSource>().Play ();
}
In the statement above it you already have a statement which checks if the tag of the object is "Pickup", what is Pickup? Is it a class? Are you trying to test if other gameobject you collide with has a class of Pickup e.g
if (other.gameObject.GetComponent<Pickup>())
{
GetComponent<AudioSource>().clip = PickUpUFO;
GetComponent<AudioSource>().Play ();
}
Your answer
Follow this Question
Related Questions
Accessing multiple audio devices 1 Answer
One of the two sound stop while other one is playing. 0 Answers
Need help coding different footstep sounds on different surfaces - Beginner` 1 Answer
Hearing sound outside of maximum range 0 Answers
Make lerpz invisible to enemies by hitting fire 2? A cloak? 1 Answer