Good day. Slowly learn Unity3D and develop a simple 2D game. When you press the pause button (call the Pause()
method), a darkened background pops up in the interface, and when you click on the background, the game continues. I decided to implement this task like this: background as a button. So that the rest of the elements outside the pause under the button were available, I decided to hang on the RigidBody2D button and move / move the background of the pause when clicking. Everything seemed to work out, but there were questions.
public Rigidbody2D back_pause = new Rigidbody2D(); bool pause = false; void Start () { //при старте сцены сразу отодвигаю фон паузы back_pause.transform.position = Vector2.left * 3000f; } public void Pause(){ if(pause == false){ //клик по кнопке "пауза" pause = true; back_pause.transform.position = Vector2.right * 3f; }else{ //клик по фону, отмена паузы pause = false; back_pause.transform.position = Vector2.left * 3000f; } }
As can be seen from the code, we move to the right by 3f, to the left by 3000f, the difference is a thousand (!) Times, and in the game everything works as it should. It is not clear ... Why is this happening? Apparently, I do not correctly understand the principle of movement and vectors ... Maybe something can be done differently?
enable = true/false
just to display an object on the stage or hide it rather than move the background somewhere to the side - Alexey Shimanskyenable = false
button does not disappear, but simply disables its functionality (it is impossible to click) and becomes “depressed”, but does not disappear ... - PolluxSetActive
confused withSetActive
)) here, look ... you can just arrange the background to full screen ru.stackoverflow.com/a/537964/191482 ........ at this background, if you like to click click - you can use eventTrigger youtu.be/3NBYqPAA5Es?t=189 and that's it. - Alexey ShimanskyeventTrigger
, I didn’t know about it!) I understand you mean the background as Image, but it’s also like the button as a layer, and if you make it invisible.CrossFadeAlpha(0, 0, false);
, through it it will be impossible to click on the elements of the game ... - PolluxCrossFadeAlpha
andSetActive(false)
... - Alexey Shimansky