Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Cast Rect to Vector4 ?

Discussion in 'Scripting' started by pabsmultiplayer, Jul 31, 2020.

  1. pabsmultiplayer

    pabsmultiplayer

    Joined:
    Sep 5, 2019
    Posts:
    11
    Is possible to cast Rect values to a vector4 ?
    Im using PackTextures , which is returning Rect but is complaining when i try to cast it

    Code (CSharp):
    1.   _uvs = (Vector4)_packedTexture.PackTextures(textures, 0, _textureResolution);
     
  2. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    573
    There is no implicit way to cast a Rect to a Vector4.

    Store the Rect in a temporary variable, and construct a new Vector4.
     
  3. pabsmultiplayer

    pabsmultiplayer

    Joined:
    Sep 5, 2019
    Posts:
    11
  4. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,130
    The issue, I assume, is there are 2 ways to define a Unity Rect. One is xLow, xHigh, yLow, yHigh; the other is xLow, yLow, width, height. You can use both on the same Rect. A cast couldn't know which one you wanted.
     
    Joe-Censored likes this.
unityunity