So i’m trying to create a script that checks if the user finger input is above or below the game object to perform a certain task.
for (int i = 0; i < Input.touchCount; ++i) {
Touch touch = Input.GetTouch(i);
if (touch.position.y > transform.position.y) {
//This is the part that gets called no matter where I click on the screen
transform.Translate (Vector2.right * -Speed * Time.deltaTime);
}
if (touch.position.y <= transform.position.y) {
transform.Translate (Vector2.right * Speed * Time.deltaTime);
}
}
This code used to work when I simply checked if the player is clicking above or below the center of the screen, however when trying to compare it to a world object the first if statement is called every time no matter where I click.
I’m not sure what the problem is but I’d assume it has something to do with comparing touch coordinates to world object coordinates.
I’ve been thinking about using ScreenToWorldPoint but as both are vector2 coordinates i’m not sure if it’s necessary.
(NOTE: this script is attached to the player)
Any help is appreciated!