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

Eric Gilbert
Eric Gilbert
1,817 Points

My Frog keeps killing himself after 3 seconds, anyone tell me why that is? Everything else seems fine.

Basically, the Frog disappears after 3 seconds of gameplay, I'm assuming it's the player health script... here is my script as is:

using UnityEngine;
using System.Collections;

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);
        }
    }
}

Thank you,

Annet de Boer
Annet de Boer
900 Points

Does it disappear no matter what you do? For example: if you keep walking around do you still have about 3 seconds gameplay? I'm guessing if it would be your PlayerHealth script that the frog would be dead within a microsecond.. or maybe you tagged the flies as "enemy" as well? just some ideas

Eric Gilbert
Eric Gilbert
1,817 Points

Yeah, disappears no matter what I do after 3 seconds, even if I don't touch any flies. I'm just going to rewatch the player health video and see if that fixes it, I'll post if I find a fix just in case anyone in the future messes up like me.