Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Trigger collider object

Discussion in 'Scripting' started by GeerRebot, May 11, 2024.

  1. GeerRebot


    Oct 13, 2022
    hello everyone, in unity I am trying to get the object with the tag Player to be detected by a box collider in istrigger, but the box collider component is on another object

    here is the script that tries to do that.

    Code (CSharp):
    1. using UnityEngine;
    3. public class ObjectTrigger : MonoBehaviour
    4. {
    5.     public Collider otherCollider;
    7.     private void OnTriggerEnter(Collider other)
    8.     {
    9.         if (other == otherCollider && other.CompareTag("Player"))
    10.         {
    11.             Debug.Log("Hello");
    12.         }
    13.     }
    14. }
  2. Kurt-Dekker


    Mar 16, 2013
    I suggest starting with any tutorial that does that.

    See the docs for your OnTriggerEnter() callback for all the things it gives you as well as the requirements necessary for it to operate.

    Work slowly take your time, there are many specific individual steps and requirements that MUST be met.

    Imphenzia: How Did I Learn To Make Games:


    Referencing GameObjects, Scripts, variables, fields, methods (anything non-static) in other script instances or GameObjects: