- Home /
I can't get a button to register a touch and execute.
So I have this function to make my character jump after a tap.
private void Jump()
{
if(Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if(touch.phase == TouchPhase.Began)
{
body.AddForce(Vector3.up * jumpForce * 2);
if (!jumpSound.isPlaying)
{
jumpSound.Play();
}
}
}
}
And then I also a button on the screen to pause game and display the menu. The problem here is the menu button does not register the touch while the player is active in the game. When the player dies I set it's gameObject.SetActive(false) and that is when the menu button works. It only registers the touch and executes when the player gameObject is not in the game scene anymore. Can anybody tell me what I'm doing wrong?
The player still jumps when I tap on the menu button. The menu button only works when the player dies and it's set to inactive in the scene. Just to make it a little more clearer.
On further testing it appears that the menu button requires the player to be active and die before it executes. I manually deactivated the player gameObject to try it and it still didn't work but it works when the player was active in the scene and dies. Just for reference here is the button script
public void ShowPause$$anonymous$$enu()
{
if(playerScript.IsDead() == false)
{
Time.timeScale = 0;
}
ui$$anonymous$$anager.Show$$anonymous$$enu();
ui$$anonymous$$anager.HideTitleScreen();
}
It is attached to the onClick function in the inspector via the Game$$anonymous$$anager gameObject which has this piece of code in in a script attached to it.
I think it´s hard to detect the problem with all this info, maybe you can provide a little bit more and I can try to go deeper in the problem because now it could be a lot of things which stop your code.
Try to check checkbox in button's inspector (don't remember which one, i'm on mobile now)
Your answer
![](https://koobas.hobune.stream/wayback/20220612172729im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
UI elements following GameObjects (3d world) 1 Answer
Trying to delay movement of a GameObject 1 Answer
How do I get my object to trigger a UI screen when it touches another object? 1 Answer
one button to hide and unihed gameobjects 0 Answers
Unity ads , can't we show video by clicking a button? 1 Answer