Search Unity

OnTriggerEnter

Discussion in 'Scripting' started by Falin, Jul 21, 2011.

  1. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Beam : MonoBehaviour {
    5.     public Transform spwanpoint;
    6.     public bool Create = true;
    7.     // Use this for initialization
    8.     void Start () {
    9.    
    10.     }
    11.    
    12.     // Update is called once per frame
    13.     void Update () {
    14.     if(Create == true){
    15.         transform.localScale += new Vector3(0, 0, 10);
    16.         }else{
    17.         }
    18.     }
    19.     void OnTriggerEnter(Collider  other){
    20.         if (other.gameObject.CompareTag( "Wall"))
    21.     {
    22.             Debug.Log("I got hit");
    23.             Create = false;
    24.         }
    25.     }
    26. }
    27.  
    The problem is that the doesn't call the things in "if (other.gameObject.CompareTag( "Wall"))".
    If I delete that if statement then when a collider enters it works. So I don't really know what I'm doing wrong.
     
    Last edited: Jul 22, 2011
  2. Dreamblur

    Dreamblur

    Joined:
    Jun 18, 2011
    Posts:
    183
    Is that script attached to the wall or the object that's supposed to enter the wall?
     
  3. ProjectOne

    ProjectOne

    Joined:
    Aug 9, 2010
    Posts:
    442
    You talk about OnTriggerEnter... but the code shows OnTriggerExit
     
  4. zine92

    zine92

    Joined:
    Nov 13, 2010
    Posts:
    1,347
    That and did you attached a rigidbody on either object that will collide?
     
  5. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    Attaching a Rigidbody did the trick thanks