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

    GeerRebot

    Joined:
    Oct 13, 2022
    Posts:
    6
    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;
    2.  
    3. public class ObjectTrigger : MonoBehaviour
    4. {
    5.     public Collider otherCollider;
    6.  
    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

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,309
    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:





    ALSO:

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

    https://forum.unity.com/threads/hel...-vars-in-another-script.1076825/#post-6944639

    https://forum.unity.com/threads/accessing-a-gameobject-in-different-scene.1103239/