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 trialMarc Martinez
12,909 PointsMy fly won't disappear
I can't get my fly to disappear on my script. I'm not sure what is wrong with my code
using UnityEngine;
using System.Collections;
public class FlyPickup : MonoBehaviour {
void onTriggerEnter(Collider other) {
// if the "Collider" other is tagged with "Player"...
if (other.CompareTag ("Player")) {
Destroy (gameObject);
}
}
}
5 Answers
Nick Pettit
Treehouse TeacherHi Marc,
My guess is that your OnTriggerEnter()
method needs to start with a capital letter. C# is a case sensitive language, so onTriggerEnter()
is different than OnTriggerEnter()
.
I hope that helps!
Amandeep Dindral
8,915 PointsAlso,
Make sure that the "FlyPickup" script has been added to to "Fly" in the Hierarchy. Nick walks you through this right in the beginning of the video.
My "FlyPickup" script wasnt added to "Fly" and the fly did not disappear when i moved the frog into it.
This may be the source of the problem for those of you who have the code typed out correctly but it's still not working.
Alejandro Chiari
1,981 PointsThank you very much!!!! Even I am not the one asking I was struggling with this too
Amandeep Dindral
8,915 PointsAlejandro Chiari You're welcome! Dont forget to up vote my answer if it was helpful.
Happy coding.
Matt Summers
3,036 PointsThanks Amandeep! Not sure what happened to my script when I created it but it somehow wasn't linked to the fly. Adding it fixed my problem.
jason chan
31,009 Pointsusing 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);
}
}
}
Alan Mattan贸
Courses Plus Student 12,188 PointsDid you add the tag "Player" or the correct tag to the game object?
Or Tray to change onTriggerEnter() to OnTriggerEnter()
Jeri Yorde
97 PointsPesky details, thanks for the tip!!! Completely missed the capital O.
Marc Martinez
12,909 PointsMarc Martinez
12,909 PointsYes!! It worked! Thank you so much I never would have guessed it.