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 trialSanam Patel
10,615 PointsFly Pickup only works for limited time
My fly pickup only works for about 5 seconds. After that, the flies won't disappear and score won't increase.
My code for FlyPickup.cs:
using UnityEngine; using System.Collections;
public class FlyPickup : MonoBehaviour {
private GameObject pickupPrefab;
void Start(){
}
void OnTriggerEnter(Collider other){
// if coliider other is tagged with the player...
if (other.CompareTag("Player")){
pickupPrefab = GameObject.Find("FlyParticles");
// add the pickup particles
Instantiate(pickupPrefab, transform.position, Quaternion.identity);
// decrement the total number of flies
FlySpawner.totalFlies--;
// update the score
ScoreCounter.score++;
Destroy(gameObject);
}
}
}