[Closed] Blocking user interaction when a prompt is displayed

Hello guys,

I'm new to Unity and please don't be too harsh with me on this if it's something simple to achieve.

I've created a "social" game-like map, with a "map-drag" functionality, "igm", and currently leveling up function on zooming in. I've also created prompts for level up and no energy.

I am currently trying to make anything unrelated to the prompts inaccessible. I've already tried with Time.timeScale = 0.0 and then 1.0 but that does not help.

Any ideas?

Thanks in advance, Eugen

more ▼

asked Dec 15, 2012 at 01:18 AM

Eugenius gravatar image

315 35 50 59

Thanks for all your help Fattie, I managed just great. I'm sure that your tutorial below will prove itself useful to many Unity newbies like me ^_^. Thanks for everything. I would close the question but I'm not sure how :).

Dec 24, 2012 at 10:54 AM Eugenius

Okey then, thank you. I'm going to continue asking as much as I can even if I don't get answers for them I'll post whatever I come up with. Merry Christmas and a Happy New Year to you too ^_^!

Dec 24, 2012 at 11:29 AM Eugenius

You have closed it ! Everything is perfect and I want you to have a great xmas. I'm sure everyone on the list is looking forwards to your next excellent question !!!

Dec 24, 2012 at 11:10 AM Fattie
(comments are locked)
10|3000 characters needed characters left

The question has been closed Apr 20, 2013 at 08:25 PM by Eugenius for the following reason:

The question is answered, right answer was accepted

3 answers: sort voted first

regarding buttons: a good possibility is,

don't use the "GUI" system at all. use IMAGE buttons that you sit there (perhaps using 2DToolkit for example).

then just write your own "buttons" (a collider with 2 lines of code). in this way you can very easily completely control everything.

bear in mind that many people feel that Unity's "GUI" system is rubbish, and just don't use it. (for me it's just a placeholder system, for development etc.)

also - there are various alternate GUI systems you can buy for €2 on the asset store. but (IMO) they are very inelegant (anything that takes more than 20 seconds to learn is not for me) - but that could be a solution for you. (I am sure they would do everything you describe, and much more)

Now, here's some totally typical - not elegant at all !!!!!! -- code for buttons.

  1. make a scene, say with some background images or whatever
  2. simply make the buttons floating in space so they look correct for the user (They could be animated, exploding, anything - they could be 2DToolkit flat sprites, or, actually just 3D spaceships, neon lights or whatever you want)
  3. now, make an empty game object called "my happy buttons". inside that game object (folder if you will), make a number of simply "cubes"... sit them sort of between your camera and the button images
  4. on the cubes, REMOVE the renderer so it's nothing more than a box collider. make these colliders fairly flat, and the correct shape of the buttons (and probably a bit bigger on iPad). those are in fact the buttons. you must carefully name those objects (the buttons) correctly (eg, from the example below, "about" etc)

To be clear, this all "shapes" better if your project is using an orthographic camera, but it will be fine in 3D camera, too. you may prefer, or have to, make another camera (ortho) to handle just the buttons - but that's just a click. it's no problem having two cameras in a scene and one should learn about this anyway. So, your "buttons" (nothing more than trivial colliders) will look like this ..

alt text

in the example code below those three colliders would be named "about" "home" etc. Note that the actual "buttons" (the colliders) do absolutely nothing - they have no code attached whatsoever. the only quantum feature they possess is their name string.

(TBC, it's perfectly OK to use spheres, planes or anything you want as the colliders there. Also, recall that people's fingers are enormous compared to the glass, accuracy is not important.)

Note as a general comment in unity you can and should learn about the physics Layers system - you can use that so that your Ninjas, etc do not collide with the "about" button! heh. /Documentation/Components/LayerBasedCollision.html

Note that the code example below includes full working code for the unity editor too. In practice, you have to have that or it's impossible to work with - often the stupid editor code takes more fooling around with than the real code for the glass on the ipad.

Note that it uses the extremely simple touch metaphor that the user must ONLY be using one finger. In practice (particularly for children's apps) you have to allow for all sorts of screwing around by users - think about how people grab the edges of screens, how chidren touch screens and so on. In practice that software takes BILLIONS of lines of code and is often more complex than the whole other software project! heh. But here you simply must touch cleanly with one finger

{To investigate the intricacies of touch programming, consider posts such as
http://answers.unity3d.com/questions/292333/how-to-calculate-swipe-speed-on-ios.html }

Recall that writing glass code is "haiku coding" or "koan coding" - the end result can be very short indeed but it is very critical and tiny changes make a huge difference.

to impress clients
you can write code all winter
but not for the glass

this is not as good as "i see an old pond / in jumps a silly froggy / i can hear the sound" but you get the idea :)

 // an impossibly trivial instructions page. it has three buttons.
 #pragma strict
 private var clicks:ClicksAudio; // just some audio for clicking, beeps, etc
 function Awake()
     theCam = GameObject.Find("_screenscam").GetComponent(Camera);
     // it's important to get the correct camera
     clicks = GameObject.Find("screensAudio").GetComponent(ClicksAudio);
 function Start()
 function buttonNamedPressed(nn:String)
     if ( nn == "about" )
         Application.LoadLevelAsync( "ScreenAbout" );
     if ( nn == "credits" )
         Application.LoadLevelAsync( "ScreenCredits" );
     if ( nn == "home" )
         Application.LoadLevelAsync( "ScreenHome" );
 function OnGUI ()
 private var touchDown:boolean;
 private var theHit : RaycastHit;
 private var theCam:Camera;
 function _basicButtons()
     if ( Input.GetMouseButtonUp(0) )
         if ( Physics.Raycast ( theCam.ScreenPointToRay( Input.mousePosition ), theHit) )
             if ( ! touchDown ) return;
             touchDown = false;
             buttonNamedPressed(theHit.collider.name );
     if ( Input.GetMouseButtonDown(0) )
         touchDown = true;
     if( Input.touches.Length > 0 )
         if ( Input.touches[0].phase == TouchPhase.Ended )
             if ( ! touchDown ) return;
             if ( Physics.Raycast ( theCam.ScreenPointToRay( Input.touches[0].position ), theHit, 10) )
                 touchDown = false;
                 buttonNamedPressed( theHit.collider.name );
         if ( Input.touches[0].phase == TouchPhase.Began )
             touchDown = true;

butts.jpg (51.4 kB)
more ▼

answered Dec 15, 2012 at 05:38 PM

Fattie gravatar image

27.4k 332 693 417

Great tutorial! I think this is actually what I was searching for. Thanks for all your help.

Dec 16, 2012 at 04:35 PM Eugenius

@Fattie I managed to trick the Unity GUI system somehow so I must ask a question before I rewrite 500 lines of code :)). Why do you consider Unity's GUI system as rubbish? I'm a newbie and that's why I'm asking so that I could maybe completely revise my code and not use GUI at all.

The tutorial you provided is more than great, I've already tried it and it works wonders :D, but calling GUI's is a bit easier in this case - considering that I cannot use the loadlevel function, because my app will not be structured on levels that need to be loaded from another scene. :)

Dec 16, 2012 at 08:39 PM Eugenius

OK, i would say it is confusing to use - it's that simple. I would urge you to ask a new question "Please explain to a new user why the GUI is held in low opinion" and you will get more intelligent answers than from me! :)

that would be a good question on thsi site

PS normally I guess you'd use "Comment" for a comment - I might move your post since the other moderators would get angry (not me of course, I'm not anal at all :) )


Dec 16, 2012 at 09:44 PM Fattie
(comments are locked)
10|3000 characters needed characters left

The GUI system is like a state machine, if you set something it's valid for everything that follows this change until you change it again or the end of the current frane.

What you need is GUI.enabled. But keep in mind you have to disable the other GUIs.

more ▼

answered Dec 15, 2012 at 01:41 AM

Bunny83 gravatar image

85.9k 31 169 438

Thanks for the reply. The thing is, I would like the GUI to still be displayed but not working. Easily put, I would like to make whatever exists beside the prompt, to inactive without making them disappear. An invisible wall or anything if something like that is possible?

[EDIT]: Sorry about that, I read through the whole wiki and it might be something i could use. I'm going to come back with a reply afterwards and tell you if it worked

Dec 15, 2012 at 11:17 AM Eugenius

If I were to move it off screen, the user wouldn't be able to see the prompt anymore. Thanks for the answer but that doesn't work in this situation.

And by static do you mean static variables? Could that be the key?

Dec 15, 2012 at 05:31 PM Eugenius

Sorry, my bad. Through prompt, I am referring to a pop-up type of window which lets the user know he has leveled up or that he has no energy (or any other information).

I am considering what you said about writing down my own button. I am probably going to stick to that for now. Thank you! @Fattie could you transform the comment to an answer so that I can mark it as the correct one?

Dec 15, 2012 at 11:41 PM Eugenius
(comments are locked)
10|3000 characters needed characters left

Cant you just use GUI object like GUI.Box to show the data in when you dont want it to be active and then use GUI.Button when you want it to be active again?

more ▼

answered Dec 15, 2012 at 01:53 PM

RobbingDaHood gravatar image

21 1 2 3

Thanks for the answer but I can't do that. As I said in the previous comment, I would like for the GUI to be visible just for the user to not be able to interact with it. Thanks anyway ^_^.

Dec 15, 2012 at 03:28 PM Eugenius
(comments are locked)
10|3000 characters needed characters left

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Dec 15, 2012 at 01:18 AM

Seen: 901 times

Last Updated: Dec 24, 2012 at 11:29 AM