Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

help to fix

Discussion in 'Scripting' started by michele2000bon, Jan 11, 2020.

  1. michele2000bon

    michele2000bon

    Joined:
    Nov 29, 2019
    Posts:
    40
    how write correctly??
    Code (CSharp):
    1. if (direction.x * direction.x > directio.x * directio.x)
    2.         {
    3.             direction.x = null; //(do not use)
    4.         }
    5.         if (direction.x * direction.x < directio.x * directio.x)
    6.         {
    7.             directio.x = null;//same
    8.         }
    9.  
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,594
    Writting correctly what?
    What data type is x? You have also misspellings.
     
  3. michele2000bon

    michele2000bon

    Joined:
    Nov 29, 2019
    Posts:
    40
    write correctly = null
     
  4. michele2000bon

    michele2000bon

    Joined:
    Nov 29, 2019
    Posts:
    40
    because it said"
    Cannot convert null to 'float' because it is a non-nullable value type
    "
     
  5. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,594
    You need set float as 0. Not null. It is numeric data type.

    Objects can be set as null. However, it isn't recommended.
     
  6. michele2000bon

    michele2000bon

    Joined:
    Nov 29, 2019
    Posts:
    40
    ok,thanks, but other ways to do not use the vector.direction???
     
  7. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
  8. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,066
    If that's a typo and the n is missing, what is this comparison then?

    if (direction.x * direction.x > directio.x * directio.x)