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 trialDarius Dennis
1,433 PointsOnce Frog is eaten sometimes bird keeps moving, frog disappears after 4-5 seconds. How to fix
I don't know whats wrong and why the bird keeps walking or why the frog just disappears after 4-5 seconds its doing it and I have been busting my butt trying to find out why please help!!
Darius Dennis
1,433 Pointsusing System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerHealth : MonoBehaviour {
public bool alive;
[SerializeField]
private GameObject pickupPrefab;
// Use this for initialization
void Start () {
alive = true;
}
void OnTriggerEnter(Collider other) {
if (other.CompareTag ("Enemy") && alive == true) {
alive = false;
//Create the pickup particles
Instantiate (pickupPrefab, transform.position, Quaternion.identity);
}
}
}
Darius Dennis
1,433 Pointsusing System.Collections; using System.Collections.Generic; using UnityEngine;
public class PickupParticlesDestruction : MonoBehaviour {
// Use this for initialization
void Start () {
//Destroy the "pcikup particles" after 5 seconds
Destroy (gameObject, 5f);
}
}
Darius Dennis
1,433 PointsI'm trying to keep the frog on the screen until eaten
Darius Dennis
1,433 PointsThe 5f is suppose to be to destroy the pick particles after 5 seconds
2 Answers
Ian Burres
250 PointsI am not familiar with unity or C#, which is what I think you're using here, but what you've written reads
if (the object is an enemy and it is alive, then its state should be set to true). Else, the state of the object should be set to false. So why are you then assigning false to alive in your OnTriggerEvent? I think this might be where your error lies, but I can't compile your code to check it for myself right now.
Ian Burres
250 PointsAlso, you're destroying the gameObject after 5 seconds, which is probably why the frog is disappearing after that amount of time has expired. Are you trying to keep the frog on screen until it is eaten? Can you be a little more specific with what you're code is supposed to accomplish?
Ian Burres
250 PointsOk, that's what I figured. Correct me if I'm wrong then, but if the object is an Enemy, and the frog is alive, you want the frog object to be destroyed. Right? If that's the case, you need to add some more code. You need to assign the value of alive (in this case false) to the frog, and then define what happens to the frog when it's state is false (or dead). Otherwise, if the frog is in a living state, nothing should happen to it. As for the bird, it looks like you might need a for loop. How long do you want it to walk?
Darius Dennis
1,433 Pointsuntil the frog collides with it
Darius Dennis
1,433 PointsDarius Dennis
1,433 Pointsusing System.Collections; using System.Collections.Generic; using UnityEngine;
public class BirdMovement : MonoBehaviour {