Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

SOLVED: Why is my float zero?

Discussion in 'Scripting' started by abojiuc, Sep 16, 2018.

  1. abojiuc


    May 29, 2017
    Whenever a object is identified it will return it's name and the match value. If the match value is too low "none" will be returned, however I don't understand why my code is returning a name if the match value returned is 0.

    String object_ID = "none";
    float match_value = 0f, longest_len = 20f, match_win_am = 0f;

    //for each object in memory
    for (int i = 0; i < object_names.Length; i++)
    match_value = object_MatchAmount(i) / longest_len;

    if ((match_value > 0.5f) && (match_value > match_win_am))
    match_win_am = match_value;
    object_ID = object_names;

    //ID found due to high score, exit for loop
    if (match_value > 0.8f)
    i = object_names.Length;

    //output text
    status_text.GetComponent<Text>().text = "ID : " + object_ID + "\nMatch % = " + match_value*100.0f + "%";

    There's no way to change the object_ID string unless match_value > 0.5, so how is it possible that I get an object_ID name and a match value of 0?

    SOLVED : the problem was finding a match value below 0.8 but higher than 0.5 and not exiting the loop right away.
    Last edited: Sep 16, 2018