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. Dismiss Notice

no work

Discussion in 'Scripting' started by Aparty_, Jan 6, 2021.

Thread Status:
Not open for further replies.
  1. Aparty_

    Aparty_

    Joined:
    Apr 27, 2020
    Posts:
    41
    1. float v=0.0f;
    2. float h=0.0f;
    3. public void OnGo(float a)
    4. {
    5. h=a;
    6. }
    7. public void OnBok(float b)
    8. {
    9. v=b;
    10. }
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,723
    Did you have a question?
     
  3. Aparty_

    Aparty_

    Joined:
    Apr 27, 2020
    Posts:
    41
    this program doesn't work, i need to fix it but i don't know how
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,723
    That's a shame. I'd like to help, but it's hard since you haven't given any kind of explanation of what you're trying to do. You also haven't explained in what way things are not working.
     
    Joe-Censored likes this.
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    There's no obvious syntax error, so you're going to actually have to say what isn't working if you want help fixing it.
     
  6. Aparty_

    Aparty_

    Joined:
    Apr 27, 2020
    Posts:
    41
    I call a variable from outside, it should assign the passed value to a global variable, but it doesn't.
     
  7. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,723
    What do you mean by "global variable"? Are you referring to "v" and "h" in this context? Can you explain why you think it isn't working?
     
    Joe-Censored likes this.
  8. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Variables h and v in your posted code will be assigned if you call their respective methods. You should add Debug.Log statements to verify the code you think is running is actually running, and verify you are checking the correct instance of this script when checking the values of h and v.

    Also, there is no "global variable" in any of the code you posted. Maybe you wanted one of these to be public static? Not sure, cause you didn't show any code where you try to actually use these variables.
     
    PraetorBlue likes this.
  9. Aparty_

    Aparty_

    Joined:
    Apr 27, 2020
    Posts:
    41
    globally change v and h
     
  10. Aparty_

    Aparty_

    Joined:
    Apr 27, 2020
    Posts:
    41
    I have already checked more than once
     
  11. Ray_Sovranti

    Ray_Sovranti

    Joined:
    Oct 28, 2020
    Posts:
    172
    But v and h aren't global. They are members of the object you're running this code on.
     
    Joe-Censored and PraetorBlue like this.
  12. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,723
    I think you have a misunderstanding about the scope of those variables. There is a different set of those variables for every instance of your class.
     
    Joe-Censored likes this.
  13. Aparty_

    Aparty_

    Joined:
    Apr 27, 2020
    Posts:
    41
    I do not know very well that everything is global or something else, that I am new to this and this code does not change the variable at startup, but the methods are called and passed the value
     
  14. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,969
    Closing for being low effort and lazy posting behaviour and a bit rude.
    Please read the rules, then start here:
    http://https://learn.unity.com

    These forums are to support and augment your learning journey. They are not a place for ask for people to "fix my stuff". Please bear that in mind before posting again.
     
    Havyx, Bunny83, Kurt-Dekker and 3 others like this.
Thread Status:
Not open for further replies.