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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Error when inputting a float.

Discussion in 'Scripting' started by Wombat85, May 8, 2015.

  1. Wombat85

    Wombat85

    Joined:
    Mar 27, 2015
    Posts:
    10
    Hey all.

    Im trying to input a float like this line:

    print(Mathf.PerlinNoise(0.1,0.0));

    or

    print(Random.Range(0.1,2.0));

    But all im getting is an error:

    Assets/Scripts/LevelManager.cs(14,31): error CS1502: The best overloaded method match for `UnityEngine.Random.Range(float, float)' has some invalid arguments
     
  2. roger0

    roger0

    Joined:
    Feb 3, 2012
    Posts:
    1,208
    if your using C#, your missing an f at the end of the float value.

    print(Mathf.PerlinNoise(0.1f,0.0f));

    print(Random.Range(0.1f,2.0f));

    you dont need to put f at the end of whole numbers. so 0.0 and 2.0 can just be 0 and 2.
     
    Wombat85 likes this.
  3. eisenpony

    eisenpony

    Joined:
    May 8, 2015
    Posts:
    971
    To clarify: C# considers a number with a decimal to be a double by default. The f is a hint to the compiler that it should be considered a float instead.
     
    LeftyRighty likes this.
  4. Wombat85

    Wombat85

    Joined:
    Mar 27, 2015
    Posts:
    10
    Thats it, thank you.