Vector2 TouchDirection(TouchListener.TouchLast touch) { if (touch != null) { return(touch.pos.x - Camera.main.transform.position.x > 0 ? Vector2.right : Vector2.left); } else { return(Vector2.zero); } }
void OnEnable() { cooldownTimer = cooldown; if (body != null) { body.velocity = Vector2.zero; } if (touches != null) { prevTouch = touches.GetLastTouch(); } }
void FixedUpdate() { TouchListener.TouchLast lastTouch = touches.GetLastTouch(); if (cooldownTimer < cooldown) { cooldownTimer += Time.fixedDeltaTime; } else { if (lastTouch != null && lastTouch != prevTouch) { body.velocity = Vector2.zero; body.position = new Vector2(lastTouch.pos.x, body.position.y); cooldownTimer = 0; } } prevTouch = lastTouch; }