Search Unity

How to set sprites width not by transform.localscale

Discussion in 'Scripting' started by kader1081, May 15, 2022.

  1. kader1081

    kader1081

    Joined:
    Oct 16, 2021
    Posts:
    379
    Hi ım getting sprites length and it's 6.25 for example ı want to change this how can ı do this.Transform.localscale doesn't usable because it does'nt represent length in float.
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,859
    Can you use
    this.Transform.localScale.x
    ?
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    The proper way to set scales:

    https://forum.unity.com/threads/onpointerenter-loose-image.1152686/#post-7396073

    NEVER set scale (or any part of scale) to zero or negative.

    NEVER use Vector2 because that makes the third term (Z) zero.

    ALWAYS use Vector3, and make sure that the .z is either 1.0f, or else your non-zero scale.

    Similarly never set scale to Vector3.zero, especially in a UI, because this will cause layout divide-by-zeros and damage all your hierarchy.
     
  4. kader1081

    kader1081

    Joined:
    Oct 16, 2021
    Posts:
    379
    no it sets localscale too