- Home /
Two buttons (Quads) are not working at a same time.
Hello,
I have created two buttons using Quad, one for acceleration & other for rotation. Both are working properly , if i press one after another. But if i press both the buttons at a same time , they are not working, only one of them is working, which is pressed first.
For it, i have used OnMouseDown & OnMouseUp to maintain state,I have used same code for both buttons. The code is as follows:
// Update is called once per frame
void Update ()
{
if (isPressed && isStarted)
{
if (canContinueIncrease)
mySpeed = mySpeed + 0.05f;
if (mySpeed >= 1f)
{
mySpeed = 1f;
canContinueIncrease = false;
}
// print("mySpeed:"+mySpeed);
}
else if (!isPressed && isStarted)
{
if (canContinueDecrease)
mySpeed = mySpeed - 0.05f;
if (mySpeed <= 0f && canContinueDecrease)
{
mySpeed = 0f;
canContinueDecrease = false;
}
// print("mySpeed:"+mySpeed);
}
}
void OnMouseDown ()
{
mySpeed = 0f;
isPressed = true;
isStarted = true;
canContinueIncrease= true;
// print("Started Up mySpeed");
}
void OnMouseUp ()
{
isPressed = false;
canContinueDecrease = true;
}.
So Please help me at where i am doing wrong.
Thanks in advance.
Answer by sarthakshah · Nov 15, 2014 at 08:32 AM
I have tried using below code,and its working.
Ray ray = Camera.main.ScreenPointToRay(touch.position);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100))
{
if(hit.transform.gameObject == gameObject)
{
upTest.mySpeed = 0f;
isPressed = true;
isStarted = true;
canContinueDecrease= true;
isSameObject = true;
}
}
Thank you so much....
Answer by screenname_taken · Nov 14, 2014 at 11:33 AM
You are using OnMousedown. Mouse down can't detect multiple touch points, for that you should instead use Input.Touches. http://docs.unity3d.com/Manual/MobileInput.html
Your answer
Follow this Question
Related Questions
Only want to detect button click event 1 Answer
Simulate click OnMouseOver / OnPointerEnter 1 Answer
Button on click needs to wait 1 Answer
Unity 4.6's button Bug? 1 Answer
Upgrade once per click on Button c# 3 Answers