Trying to make a respawn trigger, but any rigid body (or collider probably) keeps triggering it.

Hi. I’m trying to make it so that if any object passes through with the matching tag it will reload the level. However, any rigid body (or collider) is setting it off which is not the desired behavior.

Code:

using UnityEngine;
using System.Collections;

public class DamageAuroa : MonoBehaviour {

    public int PHP; //PHP = Player Health from PlayerHealth.cs script.
    public int Damage; //Amount of damage.
    public string Level;

    void Start()
    {
        PHP = GameObject.Find("Player").GetComponent<PlayerHealth>().PlayerHP;
    }

    void OnTriggerEnter(Collider coll)
    {
        if (coll.gameObject.tag == "Player")
            PHP = PHP - Damage;

        if (coll.gameObject.tag == "Ball")
            gameObject.SetActive(false);
            Application.LoadLevel(Level);

        if (PHP <= 0)
            Application.LoadLevel(Level);

    }

}

Hi,
try the second if with curly brackets.

1 Like