Does multiTouch works with Input.GetMouseButtonDown()??
If not, how can I change GetMouseButtonDown(0) to Input.Touch…? I have GUITexture button which player must hold down to make action…
Thx
Does multiTouch works with Input.GetMouseButtonDown()??
If not, how can I change GetMouseButtonDown(0) to Input.Touch…? I have GUITexture button which player must hold down to make action…
Thx
“does work” depends on your definition. mouseXXX will only react to touch 0 at all, nothing else.
As GUITexture don’t react to touches and mouse buttons, to HitTest you can easily support touches by doing the HitTest against Touch.position just as good as against Input.mousePosition
if you loop over all Input.touches you can do it for all touches in a single go basically ![]()
(keep in mind: on iOS neither mouse nor touches really have a “Down” action - you are touching the screen but thats all, there is no seperation between moving around and clicking otherwise)
I understand. But now I have GetMouseButtonDown(0) on texture button and it works like a charm. Problem is, that I can’t touch any other button when I hold this one. I need to have multitouch enabled and I think it can’t work with GetMouseButtonDown, so I need Touch instead I guess… and I don’t know what Touch is for “hold”.
There is no touch for hold. touches are just that, touches.
normally you would handle it differently and check if it was in the rect when the phase was touch began and check if its still in the rect when it stopped (ie touch phase is touch ended).
to do so the “guitexture button” needs to hold a list of touches that started in it so it can check if they also ended in it.
Ok. I have no idea how to make it working on something like this…
var guiButton : Texture2D;
var bulletPrefab : GameObject;
function Update() {
guiTexture.texture = guiButton;
if (Input.GetMouseButton(0) guiTexture.HitTest(Input.mousePosition)) {
Instantiate(bulletPrefab);
}
}
I don’t know how to get Rect of my guiButton and how to put it in correct statement for TouchPhase.Began. I need my gun to be firing when holding this button, but also need to have it in TouchPhase.Began / Ended for multitouch worknig. Because sometimes I need to tap on other button while firing…
If you want to have multi touch while still using GUITexture buttons then program them this way:
var getGUI : GUITexture;
function Awake(){
Input.multiTouchEnabled = true;
}
//ARE YOU HOLDING DOWN ON A GUITEXTURE?
for (var touch : Touch in Input.touches) {
if(touch.phase == TouchPhase.Stationary){
if(getGUI.GetScreenRect().Contains(touch.position)){
//PUT WHAT HAPPENS IF YOU HOLD THE BUTTON HERE
}
}
}//END TOUCH HOLD
//ARE YOU PUSHING DOWN ON A GUITEXTURE?
for (var touch : Touch in Input.touches) {
if(touch.phase == TouchPhase.Began){
if(getGUI.GetScreenRect().Contains(touch.position)){
//PUT WHAT HAPPENS IF YOU PUSH DOWN BUTTON HERE
}
}
}//END TOUCH PUSHING DOWN
Also here is a tip to save draw calls. You can render your whole UI using SpriteUI from CedarParkDad. Then you can still use your GUITextures, but uncheck the GUITexture flag on the object this will save a draw call but still allow the GUITexture to recieve the touch input. So your basically rendering the UI with spriteUI all in a single draw call but using invisible GUITextures to recieve the touch input ![]()
There might be a better way to do this, but hey this works for me so I’m sure it will help you out!
Cheers!
-Aaron
Hi. I am just starting out with Unity and have no scripting experience (am trying to learn JS) so please excuse any daft questions. What is meant by “TOUCH HOLD” as opposed to “TOUCH PUSHING DOWN”?
I need to create two buttons on the left of my screen for direction (one for left and one for right) then another button on the right of my screen for flying up. When the player character is on the ground there will be no movement but when it flies it will be able to move left and right. I need the flying to feel weighty (like a jet pack flying someone directly up). By tapping you will be able to hold a fairly steady level and by holding down you will fly up at ever increasing speeds to a maximum speed. Any starting points for this would be much appreciated.
Thanks ![]()
its the difference of holding down on a button, or just tapping it… touch.stationary means the finger stays on the screen in place, touch began just checks the position for if a touch occurred
Aaron: THANK YOU!!! Perfect explanation!