Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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

Discussion in 'Scripting' started by Ninamori, Nov 6, 2015.

  1. Ninamori

    Ninamori

    Joined:
    Oct 30, 2015
    Posts:
    33
    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:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class DamageAuroa : MonoBehaviour {
    6.  
    7.     public int PHP; //PHP = Player Health from PlayerHealth.cs script.
    8.     public int Damage; //Amount of damage.
    9.     public string Level;
    10.  
    11.     void Start()
    12.     {
    13.         PHP = GameObject.Find("Player").GetComponent<PlayerHealth>().PlayerHP;
    14.     }
    15.  
    16.     void OnTriggerEnter(Collider coll)
    17.     {
    18.         if (coll.gameObject.tag == "Player")
    19.             PHP = PHP - Damage;
    20.  
    21.         if (coll.gameObject.tag == "Ball")
    22.             gameObject.SetActive(false);
    23.             Application.LoadLevel(Level);
    24.  
    25.         if (PHP <= 0)
    26.             Application.LoadLevel(Level);
    27.  
    28.     }
    29.  
    30. }
    31.  
    32.  
     
  2. Okto247

    Okto247

    Joined:
    Jun 26, 2015
    Posts:
    7
    Hi,
    try the second if with curly brackets.
     
    Ninamori likes this.