- Home /
finger tap instead of mouse click?
i have unity 3.4 with license full! i build it .apk it opend on my phone but doesnt function, becz i neead a script for touch. my script is whenever i click with the mouse the box disappears. how can i change the mouse click to finger touch? this is my script
function OnMouseDown(){
//if cube's texture isn't locked texture then it loads level number which we gave it in editor
if(renderer.material.mainTexture != lock){
Application.LoadLevel(loadlevel);
}
}
Please Help!
Answer by Noah-1 · Jan 15, 2012 at 10:33 PM
Here you go!
function Update(){
//if cube's texture isn't locked texture then it loads level number which we gave it in editor
if(Input.touchCount > 0 && renderer.material.mainTexture != lock){
Application.LoadLevel(loadlevel);
}
}
im getting this error: Assets/codes/click.js(11,12): BCE0005: $$anonymous$$ identifier: 'input'. Assets/codes/click.js(11,12): BCE0005: $$anonymous$$ identifier: 'lock'. Assets/codes/click.js(11,12): BCE0005: $$anonymous$$ identifier: 'loadlevel '.
$$anonymous$$ivi I suggest you learn how to script correctly before trying to write scripts. Do some tutorials and read the docs. Then you'll know what you're doing.
Thank YOU!!!! IT WOR$$anonymous$$ED THAN$$anonymous$$ YOU! AND YES U ARE WRITE I HAVE TO LEARN $$anonymous$$ORE ABOUT SCRIPTING THAN$$anonymous$$ YOU!
Answer by DaveA · Jan 16, 2012 at 06:02 AM
// Something like this #if UNITY_IPHONE || UNITY_ANDROID if (Input.touchCount == 1) { if (Input.GetTouch(0).phase == TouchPhase.Began) { var ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position); var hit; if (collider && collider.Raycast (ray, hit, 100.0)) { OnMouseDown(); } } } #endif where OnMouseDown is your normal OnMouseDown handler
DAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVE! IT WOOOOOOOOOOOOOOOOOOOOOOOOOOOOOR$$anonymous$$ED! URE A GENIUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUS!!!!!!!!! THAAAAN$$anonymous$$ YOUUU!
AND THAN$$anonymous$$S TO EVERYONE WHO HELPED $$anonymous$$EEEEEEE! EVERY ONE THAN$$anonymous$$ YOU!
lol glad you got it working. Also you can search Unity Answers in the top right search box, there are lots of people who have had your problems before and its been resolved.
Thank You $$anonymous$$eltdown, i got a little problem now, now that this script is working fine with the boxes(3d) but for my text is not working why? i double checked everything!
Guys i fixed the problem, heheeee thannk u again if u need anythng i do my best to help u! thank u again! without u i wouldnt acheive it
Answer by reptilebeats · Jan 16, 2012 at 10:55 AM
Go look up tornado twins on youtube for good scripting lessons some are free and giva a basic understanding as long as you write the scripts not just look at them..
I only learned how to script a few months ago and i got to say its a lot easier than i thought it would be you just need to know how a computer speaks. Like learning chinese or summin.
Also look for a youtube page by willgoldstone. He gives in depth tutorials and most use scripts. Follow each one carfully then try to write the script out yourself thats how i learned
Answer by Meltdown · Jan 15, 2012 at 05:44 PM
Use
if(Input.GetMouseButtonDown(0))
{
// To determine which object was clicked use a raycast
}
hey thanks, but i dont want to make it for pc i want to make the game for android touch pads, so ins$$anonymous$$d of clicking it with a mouse i want to tap it with my finger so what script should i add or edit please i need this thank you!!
Don't post comments as answers. Post a comment under the answer you want. Like I have done on this.
I read your question correctly and yes Input.Get$$anonymous$$ouseButtonDown(0) works on IPhone and Android. Try it.
ahaa,thank you for your advicE!!!!!!!! i willl try it now! but i didnt understand this part: "To deter$$anonymous$$e which object was clicked use a raycast"
man i tried i changed and i couldnt play it on android, whenever i touch the box ntn happend this is the changd scripts:
static var turnOn:boolean=true; //when this is false we can't click on objects. it is falsing from $$anonymous$$ILLER script when we won or faild.
function Start(){ turnOn=true; }
function On$$anonymous$$ouseDown () { if(Input.Get$$anonymous$$ouseButtonDown(0)) { //if turnon is true plays attached sound then waits 0.1 second and destroys cube if(turnOn){ audio.Play(); yield WaitForSeconds (0.1); Destroy(gameObject); } } }
please can u help me please, btw what's ur e-mail this way we can chat live and understand more to each other thank youu!
Sorry I forgot to mention you need to put Input.Get$$anonymous$$ouseButtonDown(0) in your Update() function. You need to remove function On$$anonymous$$ouseDown()
Answer by reptilebeats · Jan 15, 2012 at 09:01 PM
im pretty sure you have to use input.getTouch instead, or else multiple touch is disabled. cheack out the scripting reference and scroll down there should be a page on android scripts there
so can u fix my script and write it for me so i can see it, cz im new to progra$$anonymous$$g and i rlly need this thank you
update cannot be coroutine? why am i getting this error? and guys now i lost: shoul i put input.getTouch
or
Input.Get$$anonymous$$ouseButtonDown
?? please help and thank you for all u did!!!!
Both ways work you need to learn how to script properly and read the docs. And nobody here is going to write scripts for you.
Thank You For All Ur Help!!!!!!1 $$anonymous$$ay You Achieve $$anonymous$$ore Success!!
Your answer
Follow this Question
Related Questions
Do On swipe finger? 1 Answer
Finger gesture works/fails on different devices? 0 Answers
appear android touch key board 0 Answers
Android Drag By Steps 0 Answers
Detecting onDrag over UI images 1 Answer