Question by
SynGT · Mar 20, 2016 at 05:52 PM ·
javascriptaddforceinput.touch
Input Touch Not Working Quite Right...
Ok, I'm trying to make it so that anytime the user has to hold the bottom of the screen to "float up" & then they would tap the top, while holding the bottom to get them to "float down". Ideally I'd like it to work vice versa too & if they could hold the top to "float down" & then tap the bottom to "float up". Right now, it works sometimes, but not always & I can't even tell you what triggers it to work. Sometimes you can touch the bottom & you'll be floating up but tapping up top doesn't do anything.
Here's my code. Any suggestions?
#pragma strict
var jumpSpeed : float = .002;
var fallSpeed : float = -.004;
var position : Vector2;
function Start() {
}
function Update() {
// if (Input.GetKeyDown("space")) {
if (Input.touchCount>0) {
var touch : Touch = Input.GetTouch(0);
if(touch.position.y < Screen.height/2) {
GetComponent.<Rigidbody2D>().velocity.y = jumpSpeed;
} else {
GetComponent.<Rigidbody2D>().velocity.y = fallSpeed;
}
}
}
Comment