- Home /
Touch command for GUIText on Android? OnMouseDown() for Android?
I've read all the documentation and as many answers as I can find and I haven't found the answer that works. I'm looking for the Android mobile command for OnMouseDown()(in Javascript). My first page menu has GUIText that says "Play" "Restart" Quit " etc.. and I've used the OnMouseDown() function. Does anybody know how to convert this to an Input.GetTouch function or what ever the converted code is for OnMouseDown() when using an Android mobile phone? What is the correct command function? thanx
Here's one of my scripts
var normalTex : Texture2D;
var hoverTex : Texture2D;
function OnMouseEnter() {
guiTexture.texture = hoverTex;
}
function OnMouseExit(){
guiTexture.texture = normalTex;
}
function OnMouseDown(){
Application.LoadLevel("sk6");
Time.timeScale = 1;
}
Answer by DaveA · Aug 21, 2011 at 04:58 PM
Consider using a GUI.Button instead of GUIText, as it will respond just fine to touches on Android. If you need to touch 3D objects, you need to cast a ray from the screen point into the scene and check for it hitting things. I use this instead of mousedown for everything as it ports to mobile better. Example here: http://unity3d.com/support/documentation/ScriptReference/Input-mousePosition.html
Thank you. It worked. Slow response but it works. Thanks again.
Is this part of the OnGui package? If so this is not optimized for mobile devices (OnGui calls multiple times each frame, which eats up cpu), maybe try a guiTexture. I know that is better for mobile devices, but I'm looking into how to use it.
Your answer
Follow this Question
Related Questions
Touch android iput shootting 3 Answers
mobile programming questions 1 Answer
Movies on Android. Is it possible? 2 Answers