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

what is wrong in this script ?

Discussion in 'Android' started by m-y, Jun 28, 2014.

  1. m-y

    m-y

    Joined:
    Sep 22, 2013
    Posts:
    470
    hello
    this script i use it on android platform
    it is make ( pause ) button
    then it is show a windows
    has
    Resume
    Code (JavaScript):
    1. #pragma strict
    2. var playaudio : AudioClip ;
    3. var Paused: boolean = false ;
    4. var PausedGui : GUITexture ;
    5. private var windowsrect : Rect ;
    6. //PausedGui.enabled = true ;
    7.  
    8.  
    9. public var guiStyle : GUIStyle ;
    10.  
    11. function Start ()
    12. {
    13. windowsrect = new Rect ( Screen.width/2 - 100 , Screen.height / 2 - 100, 200 , 150 ) ;
    14.  
    15.  
    16.  
    17.  
    18.  
    19. }
    20.  
    21. function OnMouseUp ()
    22. {
    23. audio.PlayOneShot(playaudio) ;
    24. //if ( Input.GetKeyUp("p"))
    25. //{
    26. if( Paused == true )
    27. {
    28. Paused = false ;
    29. //PausedGui.enabled = false ;
    30. }
    31. else
    32. {
    33. Paused = true  ;
    34. // PausedGui.active = false ;
    35.  
    36.      
    37. //  PausedGui.enabled = true;
    38.  
    39. }
    40. if ( Paused == true )
    41. {
    42. Time.timeScale = 0  ;
    43. }
    44. else
    45. {
    46. Time.timeScale = 1.0 ;
    47. }
    48. }
    49. private  function OnGUI ()
    50. {
    51. if ( Paused)
    52. {
    53. windowsrect = GUI.Window(0,windowsrect , WindowsFunc, "Pause Menu" ) ;
    54. }
    55. else
    56. {
    57.  
    58. }
    59. }
    60. private function WindowsFunc (id : int    )
    61.   {
    62.  
    63.   if ( GUILayout.Button("Resume", GUILayout.Width(180) , GUILayout.Height(50)))
    64.   {
    65.   Time.timeScale = 1 ;
    66. Paused = false ;
    67.   }
    68.  
    69.   if ( GUILayout.Button ("Main Menu", GUILayout.Width(180) , GUILayout.Height(50)))
    70.   {
    71.  
    72.   Application.LoadLevel ("MainMenuScene" ) ;
    73.   }
    74.   }
    75.  
    76.  
    77.  
    and
    main menu

    when i press by mouse ( resume ) or ( main menu )
    it is working well
    but when i press it by touch
    it is not responding at all
    so what should i need to edit to it
    to make it able on touch on android ?
     
  2. jefjohms

    jefjohms

    Joined:
    Feb 8, 2014
    Posts:
    1
  3. brzozowsky

    brzozowsky

    Joined:
    Sep 12, 2011
    Posts:
    39
    if(Input.touchCount >=1)
    {
    // Do something
    }