Search Unity

Checking RectTransform position of an object

Discussion in 'Scripting' started by BMM7, Sep 20, 2017.

  1. BMM7

    BMM7

    Joined:
    Sep 20, 2017
    Posts:
    54
    Hello!

    How do I write a script to check if, for example, the X position of an object's RectTransform is 0?

    And to check the value of the Y and Z positions?
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Try this: https://unity3d.com/learn
    Unity introduction stuff + scripting introduction would probably help you.

    Code (csharp):
    1.  
    2. RectTransform rt = GetComponent<RectTransform>(); // this could be 'transform' instead, too.
    3. print("rt position = " + rt.transform.position);
    4. print("rt local pos = " + rt.transform.localPosition);
    5. print("rt x/y/z = " + rt.transform.position.x + " " + rt.transform.position.y + " " + tr.transform.position.z);
    6. // etc..
    7.  
    And sorry, if you're looking to 'compare' to 0 you might want to include a small offset, like .1 or something :)