- Home /
Simultaneous button presses
Hello
I want to make my two buttons work parallely..
In my case ,,I am having One button which allows my player to move left and right and other is fire button which continuously fire..
PlayerMove Button works with Input.GetMouseButtonDown(0) in Update() and for fire it is GUI button in OnGUI()..
Now i wants to make this two button works togather..
For that i want some ideas.. as i search but did not get anything..
So please help me..
Thanks for your support and advice..
Your question is too hard to understand. Submit your code and screenshots to illustrate how your controls work.
Do you mean you want both buttons to be pressed simultaneously? I'm not sure how you mean to do that if they are both in different places on the screen, unless you expect the cursor to be in two places at the same time.
yeah right i have kept both of them at diff place.. but at a time,only single button is working even if i press both buttons..
Answer by Ekta-Mehta-D · Apr 18, 2013 at 10:59 AM
I have solved my problem using touch..
for(var touch : Touch in Input.touches)
{
if(touch.phase == TouchPhase.Stationary)
{
var hit : RaycastHit;
var ray : Ray = Camera.mainCamera.ScreenPointToRay(touch.position);
if (Physics.Raycast(ray,hit))
{
if(hit.collider.gameObject.GetComponent("ButtonId"))
{
buttonPressed = hit.collider.gameObject.GetComponent("ButtonId");
if(buttonPressed.id == "RightMove")
{
MovePlayerRight();
Debug.Log("right");
}
if(buttonPressed.id == "Fire" && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
HandleBullet();
}
if(buttonPressed.id == "LeftMove")
{
MovePlayerLeft();
Debug.Log("left");
}
}
}
}
}
Now my player moves also and fire also parallely on button touch/press.. This all i want to do..
Thanks..
Nowhere in this question do you mention touch. This issue was raised in one of the comments :
Do you mean you want both buttons to be pressed simultaneously? I'm not sure how you mean to do that if they are both in different places on the screen, unless you expect the cursor to be in two places at the same time.
The fact that you are using a touch input is essential information to answering your question. Please write better questions in future, include all the relevant information.
ohk sir.. next time i will take care..but i was not knowing this thing can possible through touch.. but i tried and i got my result.. its ok.. you are right.. i will be careful next time.. and sorry..
Answer by Linus · Apr 17, 2013 at 10:36 AM
Use a boolean variable and set it to true when button 1 is pressed. Then do a check in the second button detection code to see if the first one is pressed.
Remember to reset it to false when appropriate
In your example, you will need to find out what is triggered first. The button or the mouse down, some debug log testing should tell you that.
Your answer
Follow this Question
Related Questions
reading user's keyboard input inside a GUI Input field and saving it into variables for later use? 2 Answers
Simultaneous touch inputs do not always work 0 Answers
Input.mouse position on GUI Textures 2 Answers
Making GuiButton trigger on ps3 controller input 0 Answers
Touch Input with GUI Texture 1 Answer