Search Unity

Type casting problem [Solved]

Discussion in 'Scripting' started by Marscaleb, Jul 29, 2014.

  1. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,037
    I'm using the code:
    Code (CSharp):
    1. int wipeLine;
    2. float wipeTimer;
    3. wipeLine = (Screen.width + 64) * wipeTimer;
    And getting the error:
    I guess I'm too used to JavaScript. I don't know how to resolve this issue in C#.

    The equation needs to calculate as a float and then change the final result into an int. How do I get it to do that?
     
  2. THoeppner

    THoeppner

    Joined:
    Oct 10, 2012
    Posts:
    205
    Just cast the whole expression to an int:

    Code (CSharp):
    1. wipeLine = (int)((Screen.width + 64) * wipeTimer);
     
  3. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,037
    Well, that worked! Thank you.