Search Unity

how to internally calculate random number....i am implementing game like braintuner2.

Discussion in 'Scripting' started by sidhesh, Dec 3, 2012.

  1. sidhesh

    sidhesh

    Joined:
    Nov 6, 2012
    Posts:
    51
    now suppose for example 2 + 3 = 6 (2,3,6 numbers are generated randomly.....)i wil be using two GUIBUTTON one for right and other for wrong...now internally i should calculate answer for 2 + 3 = 5....and depending upon user pressing right or wrong button...if user presses wrong button for above example then my game should display next number...BUT MY POINT IS HW TO CALACULATE original answer internally.......here is code...

    Code (csharp):
    1.  
    2. #pragma strict
    3.  
    4. var rand:int;
    5.  
    6. function Start()
    7.  
    8. {
    9.  
    10.  
    11. rand = Random.Range(0, 10);
    12.  
    13. }
    14.  
    15. function OnGUI()
    16. {
    17.  
    18.  
    19. //var rand:int;
    20. //rand = Random.Range(0, 10);
    21. //GUI.Label(Rect(20,20,100,30),rand.ToString());
    22. GUI.Box (Rect (30,5,25,30), rand.ToString());//first random number
    23. Debug.Log(rand);
    24. GUI.Box (Rect (60,5,25,30),"+");//for +symbol
    25.  
    26. GUI.Box (Rect (120,5,25,30),"=");//for equals to
    27.  
    28.  
    29.  
    30. //var inter : int;
    31.  
    32. }
    33.  
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,532
    If you're displaying the two numbers to be added, you then have those numbers. Just sum them together in your code and compare them to the random answer. If they're the same, right it the answer, if they're different wrong is the answer.
     
  3. sidhesh

    sidhesh

    Joined:
    Nov 6, 2012
    Posts:
    51
    can u help me with code....plz...and these are random numbers.....
     
  4. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,532
    you generated random numbers. So you have them. Just add them. (though I don't see where you generated the numbers for adding, only generated the possible answer. Your code you posted is way incomplete)

    I'm not going to write this code for you, I'm doing you NO favor by doing that, but instead a dis-service as you'll still not know how to code it yourself.
     
  5. sidhesh

    sidhesh

    Joined:
    Nov 6, 2012
    Posts:
    51
    thnx alot lordofduct...... Done with it by using urs logic.......