Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Game Development How to Make a Video Game Pickups Script the Fly Pickup

Thale van der Sluijs
Thale van der Sluijs
1,756 Points

Fly doesn't dissapear

I double-checked my code but the fly still won't dissapear. this is my code:

          <p>using UnityEngine;
using System.Collections;

public class FlyPickUp : MonoBehaviour {

    void OnTriggerEnter(Collider other) {
        // if collider other is tagged with player ... excecute code
        if (other.CompareTag ("Player")){
            Destroy (gameObject);
        }
    }
}</p>
          ```

4 Answers

Justin Molyneaux
Justin Molyneaux
13,329 Points

Thale, your code should work. But it is possible that you did not tag the player object with the tag "Player" in the Inspector window. Can you double check?

To do this:

  1. In the Hierarchy window select the Player Object.
  2. Then in the Inspector Window, makes sure that the "Tag" drop down menu reads "Player".

See https://drive.google.com/open?id=0B6kqBt-oYw0FZk9aTkZTUHdNc1k

Thale van der Sluijs
Thale van der Sluijs
1,756 Points

Hi Justin Molyneaux,

I just fixed it but the fly still doesn't dissapear... The program is giving a error: The referenced script on this Behavior (Game object 'Fly') is missing! Maybe this helps you.

Thanks already, Thale van der Sluijs

taylornajjar
taylornajjar
15,807 Points

When you add the script to the Fly object, make sure you click the "Apply" button (at the top right in the Inspector window) so the script is applied to the prefab. Is it possible that's your problem?

Thale van der Sluijs
Thale van der Sluijs
1,756 Points

hey taylornajjar,

Your tip didn't fix it but I found the error! I exidently called the class FlyPickUp instead of FlyPickup. I am from the Netherlands so sometimes I forget stuff.

thanks for the help! Thale van der Sluijs