Search Unity

How did I mess up OnTriggerEnter?

Discussion in 'Scripting' started by Anon1234, Nov 23, 2014.

  1. Anon1234

    Anon1234

    Joined:
    Feb 17, 2014
    Posts:
    78
    Plain situation. There is:
    - a plane (as ground)
    - a cube (trigger element), has rigidbody, name is "ignite", is a trigger, doesn't use gravity, is not kinematic, tagless.
    - player controller (standard player controller "asset" included in Unity 4.5)

    I "created" following script:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class impacting : MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.        
    9.     }
    10.    
    11.     // Update is called once per frame
    12.     void Update() { }
    13.     void OnTriggerEnter(Collider firebox) {
    14.         if (firebox.gameObject.name == "ignite") {
    15.             Debug.Log("Hit!");
    16.         }
    17.     }
    18. }
    I opened my console in Unity3D, but it didn't work. I did drag the script from Project folder view to First Person Controller. I wanted to get it to work, but it doesn't seem to like me. Any ideas?
     
  2. Fraconte

    Fraconte

    Joined:
    Dec 6, 2013
    Posts:
    327
    The script have to be in the trigger (the cube) and firebox is the collider who enter the trigger, so "ignite" have to be the name of the player.
    Also check that the trigger's collider is larger than other colliders (if any).
     
    Last edited: Nov 23, 2014
    Anon1234 likes this.
  3. Anon1234

    Anon1234

    Joined:
    Feb 17, 2014
    Posts:
    78
    Why haven't I thought of that! Thank you Sir!