Search Unity

  1. Unity 2019.1 beta is now available.
    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. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

SOLVED: Why is my float zero?

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

  1. UniversalGesture

    UniversalGesture

    Joined:
    May 29, 2017
    Posts:
    93
    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