Search Unity

float conversion in c# rect constructor

Discussion in 'Scripting' started by gabrielh, Apr 1, 2008.

  1. gabrielh

    gabrielh

    Joined:
    Feb 24, 2008
    Posts:
    51
    Hi!

    I prefer scripting in C#, but I have a really annoying problem. Every time I am defining a rect for a GUI controls (e.g. GUI.Label(new Rect(...)) I have to cast all positioning values to float, so:

    new Rect((float)(Screen.widht/2), (float)(30), ...)

    Is there a way to do this with less code-blow up?

    Thanks
    Gabriel
     
  2. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    You sure C# won't automatically cast from integer to float? If not - you could do something like this:

    new Rect( Screen.width/2.0f, 30.0f, ...)
     
  3. gabrielh

    gabrielh

    Joined:
    Feb 24, 2008
    Posts:
    51
    thanks! makes the code much more readable like that :)