Search Unity

Resolved How do I check the position of an object? / ¿Como compruebo la posición de un objeto?

Discussion in 'Scripting' started by bruedlp, Apr 17, 2021.

  1. bruedlp

    bruedlp

    Joined:
    Apr 17, 2021
    Posts:
    5
    I know it must be a very easy thing, and I came up with some ideas but they didn't work, I'm new.
    I want to check the position of an object, that is, if such object is in x position, so a thing happens.
    (sorry the english)

    Sé que debe ser algo muy fácil, y se me ocurrieron algunas ideas pero no funcionaron, soy nuevo.
    Quiero comprobar la posición de un objeto, es decir, si tal objeto está en x posicion, que pase tal cosa.
     
  2. There is something like this (very crude example):
    Code (CSharp):
    1. [SerializeField] float Vector3 targetPosition;
    2.  
    3. void Update() {
    4.     bool closeEnough = Mathf.Approximately(targetPosition.x, transform.position.x)
    5.         && Mathf.Approximately(targetPosition.y, transform.position.y)
    6.         && Mathf.Approximately(targetPosition.z, transform.position.z);
    7.     if (closeEnough) {
    8.         Debug.Log("I was close enough!");
    9.     }
    10. }
     
  3. bruedlp

    bruedlp

    Joined:
    Apr 17, 2021
    Posts:
    5
    Thank you so much!
     
  4. Leonardo_M

    Leonardo_M

    Joined:
    Sep 20, 2022
    Posts:
    1
    use a trigger